Created
January 3, 2017 10:47
-
-
Save frontsideair/87ea85e640ca62caaae87d29fc0d33d9 to your computer and use it in GitHub Desktop.
Simple implementation of push/pop with comma operator, function scope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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