Skip to content

Instantly share code, notes, and snippets.

@myfonj
Last active July 13, 2020 19:54
Show Gist options
  • Save myfonj/41967b341ae362f1693098cae6abce83 to your computer and use it in GitHub Desktop.
Save myfonj/41967b341ae362f1693098cae6abce83 to your computer and use it in GitHub Desktop.
Array methods cheatsheet text transcript
Array methods cheatsheet (JS tips by @sulco)
map(square → circle)
In: black, tan, red and blue squares.
Out: black, tan, red and blue circles.
filter(square)
In: black and tan squares, red circle and blue square.
Out: black, tan, and blue squares.
find(square)
In: black and tan circles, red square and blue square.
Out: red square.
findIndex(square)
In: black circle, tan circle, red circle, blue square.
Out: number three.
fill(1, green circle)
In: black square, tan square, red square, blue square.
Out: black square, three green circles.
copyWithin(2, 0)
In: black, tan, red and blue squares.
Out: black and tan squares, followed by another black and tan squares.
some(square)
In: black circle, tan and red squares and blue circle.
Out: true.
every(square)
In: black and tan squares, red circle and blue square.
Out: false.
reduce(acc + curr)
In: black, tan, red, and blue squares.
Out: each square stacked at each other.
Array methods cheatsheet
- "map" method:
Input: purple square, teal square, orange square, blue square.
Operation: map(square → circle).
Product: purple circle, teal circle, orange circle, blue circle.
- "filter" method:
Input: purple square, teal square, orange circle, blue square.
Operation: filter(square).
Product: purple square, teal square, blue square.
- "find" method:
Input: purple circle, teal circle, orange square, blue square.
Operation: find(square).
Product: orange square.
- "findIndex" method:
Input: purple circle, teal circle, orange circle, blue square.
Operation: findIndex(square).
Product: number three.
- "fill" method:
Input: purple square, teal square, orange square, blue square.
Operation: fill(1, green circle).
Product: purple square, green circle, green circle, green circle.
- "copyWithin" method:
Input: purple square, teal square, orange square, blue square.
Operation: copyWithin(2, 0).
Product: purple square, teal square, purple square, teal square.
- "some" method:
Input: purple circle, teal square, orange square, blue circle.
Operation: some(square).
Product: true.
- "every" method:
Input: purple square, teal square, orange circle, blue square.
Operation: every(square).
Product: false.
- "reduce" method:
Input: purple square, teal square, orange square, blue square.
Operation: reduce(acc + curr).
Product: all squares stacked at each other.
JS tips by @sulco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment