Skip to content

Instantly share code, notes, and snippets.

@frontsideair
Created January 3, 2017 10:47
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 frontsideair/87ea85e640ca62caaae87d29fc0d33d9 to your computer and use it in GitHub Desktop.
Save frontsideair/87ea85e640ca62caaae87d29fc0d33d9 to your computer and use it in GitHub Desktop.
Simple implementation of push/pop with comma operator, function scope
const pop = (arr, tmp) => (tmp = arr.slice(0), tmp.pop(), tmp)
const push = (arr, item, tmp) => (tmp = arr.slice(0), tmp.push(item), tmp)
// Can you see why and how this works? Does it really? Can you guess if it's pure or impure?
// Does it modify any of its arguments, or pollute global scope?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment