Created
April 17, 2013 16:18
-
-
Save BrianHicks/5405612 to your computer and use it in GitHub Desktop.
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
//// SLICE //// | |
// first we need an object | |
x = [1, 2, 3] | |
// slicing gets a new value, without modifying the old one | |
x.slice(0, 2) == [1, 2] // true | |
x == [1, 2, 3] // true | |
// so we can call it multiple times and x is never mutated | |
x.slice(0, 2) | |
x == [1, 2, 3] | |
//// SPLICE //// | |
// splice modifies things... so to remove the last element: | |
x.splice(2, 1) == [3] // true | |
x == [1, 2] // true | |
// and calling splice again yields a different value | |
x.splice(2, 1) == [] // true | |
x == [1, 2] // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment