Skip to content

Instantly share code, notes, and snippets.

@isdampe
Created August 5, 2019 22:59
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 isdampe/2c0dd564a398df60cee5beb986c73efd to your computer and use it in GitHub Desktop.
Save isdampe/2c0dd564a398df60cee5beb986c73efd to your computer and use it in GitHub Desktop.
let theArray = [5, 9, 3, 15, 41, 2, 19];
function arrayShift(arr, idx) {
console.log("Starting array is");
console.log(theArray);
for (let i=idx; i<arr.length - 1; ++i) {
console.log("Step");
theArray[i] = theArray[i + 1];
console.log(theArray);
}
theArray.pop();
console.log("Done, result was")
console.log(theArray);
}
// int main(void) { ...
console.log("Will remove 15");
arrayShift(theArray, theArray.indexOf(15));
console.log("Will remove 9");
arrayShift(theArray, theArray.indexOf(9));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment