Skip to content

Instantly share code, notes, and snippets.

@Kielx
Created June 6, 2020 18:26
Show Gist options
  • Save Kielx/21c29ea249c690aa35cc9d787b719daa to your computer and use it in GitHub Desktop.
Save Kielx/21c29ea249c690aa35cc9d787b719daa to your computer and use it in GitHub Desktop.
makeArrayConsecutive scrimba coding challange
// 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