Member-only story
JavaScript for Dummies (Me): Part 4
Lessons in getting schooled by people smarter than I.
5 min readMay 30, 2018
Now that our program at New York Code + Design Academy has ended, I have time to dig back into daily JavaScript challenges. Today’s problem from codefights.com:
Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.ExampleFor statues = [6, 2, 3, 8], the output should be
makeArrayConsecutive2(statues) = 3.Ratiorg needs statues of sizes 4, 5 and 7.
My Thought Process
- Sort the array from lowest to highest.
- Identify the missing numbers.
- Tally the number of missing numbers.
Seems simple enough. But the first problem I ran into in trying to sort the array is that, according to MDN’s docs, “The sort()
method sorts the elements of an array in place and returns the array.” For example: