Skip to content

Instantly share code, notes, and snippets.

@SimeonC
Last active February 10, 2026 01:01
Show Gist options
  • Select an option

  • Save SimeonC/163928f30fe2b5b65120c41012a60ec2 to your computer and use it in GitHub Desktop.

Select an option

Save SimeonC/163928f30fe2b5b65120c41012a60ec2 to your computer and use it in GitHub Desktop.
Interview question from Cassidy's newsletter.
function moveNums(arr, t) => {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === t) {
arr.splice(i, 1);
arr.push(t);
}
}
return arr;
}

Given an integer array and a number n, move all of thens to the end of the array while maintaining the relative order of the non-ns. Bonus: do this without making a copy of the array!

$ moveNums([0,2,0,3,10], 0)
$ [2,3,10,0,0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment