Skip to content

Instantly share code, notes, and snippets.

@rphansen91
Created December 4, 2019 05:47
Show Gist options
  • Save rphansen91/7f88beeb3282797851789c3e12a524ba to your computer and use it in GitHub Desktop.
Save rphansen91/7f88beeb3282797851789c3e12a524ba to your computer and use it in GitHub Desktop.

Make Consecutive Array

Given the following array, [6, 2, 3, 8] find the minimum number of entries needed to make the array consecutive

[2, 3, *4*, *5*, 6, *7*, 8] = 3 entries needed. 

Test cases

makeConsecutive([0, 2]) === 2
makeConsecutive([5, 4, 6]) === 0
makeConsecutive([6, 3]) === 2
makeConsecutive([1]) === 0
makeConsecutive([1, 2, 3, 100]) === 96
makeConsecutive([1000, 100, 10, 1]) === 996

// Fill out the following code to satisfy the above tests
function makeConsecutive () {
  return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment