Skip to content

Instantly share code, notes, and snippets.

@BrianHicks
Created April 17, 2013 16:18
Show Gist options
  • Save BrianHicks/5405612 to your computer and use it in GitHub Desktop.
Save BrianHicks/5405612 to your computer and use it in GitHub Desktop.
//// 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