Skip to content

Instantly share code, notes, and snippets.

@chygoz2
Last active April 24, 2021 00:30
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 chygoz2/540ca2dcf141b8340b3194b4eeb5da8b to your computer and use it in GitHub Desktop.
Save chygoz2/540ca2dcf141b8340b3194b4eeb5da8b to your computer and use it in GitHub Desktop.
Algo friday 2 solution
function removeInstance(nums, val) {
if (!Array.isArray(nums)) throw new Error('Invalid input')
return nums.filter(entry => entry !== val).length
}
@meekg33k
Copy link

Very well said and I totally agree that in terms of algorithm complexity, O(n/2) is effectively O(n). You got a clean solution nevertheless!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment