Alphabet Soup

You are working on a team that is building an app that stores information about a wocket making machines. Each wocket requires a number of widgets to be plugged into machines to make them. You have been tasked with assigning the letter associated with a plug on the wocket making machine with the widget going into it.

The Challenge

For this challenge we’ll be working with arrays and sorting. We’ll sort the array of objects with letters into alphabetical order so that we can find the next letter or any missing ones.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[
{
"Name": "Wonky Widget",
"Color": "Brown",
"SerialNumber": "1234",
"Slot": "A"
},
{
"Name": "Wild Widget",
"Color": "Purple",
"SerialNumber": "4321",
"Slot": "B"
},
{
"Name": "Weird Widget",
"Color": "Green",
"SerialNumber": "2343",
"Slot": "C"
}
]

Creating a Test Case

No matter the level you choose to work with write a test case before you start your code. Then write just enough code to pass the test. Once you have passing code refactor to pass other test cases.

Level 1

Your task for level 1 is to take an array of letters and find then find the next letter in the array.

1
['A', 'B', 'C', 'D']

A Step Further

Going a step further add a new widget to the array of widgets. In order to add it you’ll need to find the last letter for a slot in a widget in the array of widgets and then get the next letter to

1
2
3
4
5
{
"Name": "Weeping Widget"
"Color": "Blue"
"SerialNumber": "9876",
}

Level 2

For level 2 you’ve been asked to take into account the fact that there may be more than 26 widgets on a machine. After the last letter “Z” use double letters “AA”, “AB”, “AC”, then “BA”, “BB”, “BC”, etc.

A Step Further

Going a step further make is so that it can keep going infinitely adding extra letters so that you have “AAA” or “AAAA”.

Level 3

For level 3 you find out that they may have removed some widgets from the wocket machine. So before adding a new widget find out if there are any letters missing in the sequence and fill in the missing spots with the new widget.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[
{
"Name": "Wonky Widget",
"Color": "Brown",
"SerialNumber" : "1234",
"Slot": "A"
},
{
"Name": "Wild Widget",
"Color": "Purple",
"SerialNumber": "4321",
"Slot": "B"
},
{
"Name": "Weird Widget",
"Color": "Green",
"SerialNumber": "2343",
"Slot": "D"
}
]

A Step Further

Going a step further ensure no two widgets have the same slot letter.