Created
June 6, 2020 18:26
-
-
Save Kielx/21c29ea249c690aa35cc9d787b719daa to your computer and use it in GitHub Desktop.
makeArrayConsecutive scrimba coding challange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function makeArrayConsecutive returns the number of missing items between smallest | |
// and largest number in provided array | |
const makeArrayConsecutive = function (array) { | |
array.sort((a, b) => a - b); | |
let myArray = []; | |
for (i = array[0]; i < array[array.length - 1]; i++) { | |
myArray.push(i); | |
} | |
myArray = myArray.filter(function (el) { | |
return !array.includes(el); | |
}); | |
return myArray.length; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment