Created
September 23, 2016 20:58
-
-
Save dnasca/13d1a1f986090fcd0f936b1892ea83f2 to your computer and use it in GitHub Desktop.
Pure Function
This file contains hidden or 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
// pure function | |
// evaluates the same result given the same args | |
// doesn't depend on and doesn't modify the states of variables outside it's scope | |
// no side effects (mutations, async reqs) | |
var foods = ['beans', 'rice', 'pizza', 'pineapple'] | |
// slice (shallow modified copy of array) vs splice (modifies original array) | |
foods.slice(0,3) //returns ['beans', 'rice', 'pizza'] | |
foods.slice(0,3) //returns ['beans', 'rice', 'pizza'] | |
foods.slice(0,3) //returns ['beans', 'rice', 'pizza'] - return predictable | |
foods.splice(0,3) //returns ['beans', 'rice', 'pizza'] | |
foods.splice(0,3) //returns ['pineapple'] | |
foods.splice(0,3) //returns [] - same args, different results. impure. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment