Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created April 13, 2020 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/7db298af1999720d8f40eded5e19f1c7 to your computer and use it in GitHub Desktop.
Save Nicknyr/7db298af1999720d8f40eded5e19f1c7 to your computer and use it in GitHub Desktop.
CodeSignal - Remove Array Part
/*
Remove a part of a given array between given 0-based indexes l and r (inclusive).
Example
For inputArray = [2, 3, 2, 3, 4, 5], l = 2, and r = 4, the output should be
removeArrayPart(inputArray, l, r) = [2, 3, 5].
*/
function removeArrayPart(inputArray, l, r) {
// Delete from l until r - l + 1 to include r
// if l = 2 and r = 4
// Subtract 4 - 2 = 2
// Add 2 + 1 so that 3 numbers are deleted i.e. inclusive of r
inputArray.splice(l, r - l + 1);
return inputArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment