Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save oldmonad/c4da0adef4ddbfe9bce35bcdba06e662 to your computer and use it in GitHub Desktop.

Select an option

Save oldmonad/c4da0adef4ddbfe9bce35bcdba06e662 to your computer and use it in GitHub Desktop.

Revisions

  1. @ljharb ljharb revised this gist Jul 16, 2021. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    # Array Iteration

    https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    ## Intro
  2. @ljharb ljharb revised this gist Dec 15, 2019. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,19 @@ Below are some of the methods that *iterate* - in other words, that operate on t

    All array methods iterate in what is traditionally called "left to right" - more accurately (and less ethnocentrically) from index `0`, to index `length - 1` - also called "start" to "end". `reduceRight` is an exception in that it iterates in reverse - from `end` to `start`.

    ## Special Mention: `Array.from`

    `Array.from`, introduced in ES6/ES2015, accepts any array, "arraylike", or "iterable". An "arraylike" object is anything with a `length`, which includes arrays, strings, and DOM NodeLists (as produced by `document.querySelectorAll`, eg). An "iterable" is anything that has a `Symbol.iterator` method, which includes arrays, strings, NodeLists, Maps, Sets, and potentially many more.

    To efficiently convert any non-array into one for the purpose of using the below methods, you can utilize `Array.from`'s "mapper" argument:
    ```js
    const tagNames = Array.from(document.querySelectorAll('.someClass'), (el) => el.tagName);

    const codePointValues = Array.from('some string with 💩 emoji 💩!', (codePoint) => codePoint.codePointAt(0));

    const mapValues = Array.from(map, ([key, value]) => value);
    ```

    -------

    `forEach`:
  3. @ljharb ljharb revised this gist Dec 21, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -114,7 +114,7 @@ console.log(found === objects[1]); // true
    - _example use case_:
    ```js
    const objects = [{ id: 'a' }, { id: 'b' }, { id: 'c' }];
    const foundIndex = objects.find(function (item) {
    const foundIndex = objects.findIndex(function (item) {
    return item.id === 'b';
    });
    console.log(foundIndex === 1); // true
  4. @ljharb ljharb revised this gist Dec 21, 2016. 1 changed file with 64 additions and 2 deletions.
    66 changes: 64 additions & 2 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,64 @@
    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    ## Intro
    JavaScript Arrays have lots of built in methods on their prototype. Some of them *mutate* - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. This means, to perform a single operation on the list as a whole ("atomically"), and to return a *new* list - thus making it much simpler to think about both the old list and the new one, what they contain, and what happened during the operation.
    JavaScript Arrays have lots of built in methods on their prototype. Some of them *mutate* - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, `List` is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a *new* list - thus making it much simpler to think about both the old list and the new one, what they contain, and what happened during the operation.

    Below are some of the methods that *iterate* - in other words, that operate on the entire list, one item at a time. When you call them, you provide a *callback function* - a single function that expects to operate on one item at a time. Based on the Array method you've chosen, the callback gets specific arguments, and may be expected to return a certain kind of value - and (except for `forEach`) the return value determines the final return value of the overarching array operation. Although most of the methods are guaranteed to execute for *each* item in the array - for all of them - some of the methods can stop iterating partway through; when applicable, this is indicated below.

    All array methods iterate in what is traditionally called "left to right" - more accurately (and less ethnocentrically) from index `0`, to index `length - 1` - also called "start" to "end". `reduceRight` is an exception in that it iterates in reverse - from `end` to `start`.

    -------

    `forEach`:
    - _callback answers_: here’s an item. do something nutty with it, i don't care what.
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: nothing - in other words, `undefined`
    - _example use case_:
    ```js
    [1, 2, 3].forEach(function (item, index) {
    console.log(item, index);
    });
    ```

    `map`:
    - _callback answers_: here’s an item. what should i put in the new list in its place?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: list of new items
    - _example use case_:
    ```js
    const three = [1, 2, 3];
    const doubled = three.map(function (item) {
    return item * 2;
    });
    console.log(three === doubled, doubled); // false, [2, 4, 6]
    ```

    `filter`:
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: should i keep this item?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: list of kept items
    - _example use case_:
    ```js
    const ints = [1, 2, 3];
    const evens = ints.filter(function (item) {
    return item % 2 === 0;
    });
    console.log(ints === evens, evens); // false, [2]
    ```

    `reduce`:
    - _callback answers_: here’s the result from the previous iteration. what should i pass to the next iteration?
    - _callback gets these arguments_: `result`, `item`, `index`, `list`
    - _final return value_: result of last iteration
    - _example use case_:
    ```js
    // NOTE: `reduce` and `reduceRight` take an optional "initialValue" argument, after the reducer callback.
    // if omitted, it will default to the first item.
    const sum = [1, 2, 3].reduce(function (result, item) {
    return result + item;
    }, 0); // if the `0` is omitted, `1` will be the first `result`, and `2` will be the first `item`
    ```

    `reduceRight`: (same as `reduce`, but in reversed order: last-to-first)

    @@ -36,24 +68,54 @@ Below are some of the methods that *iterate* - in other words, that operate on t
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: `true` after the first item that meets your criteria, else `false`
    - **note**: stops iterating once it receives a truthy value from your callback.
    - _example use case_:
    ```js
    const hasNegativeNumbers = [1, 2, 3, -1, 4].some(function (item) {
    return item < 0;
    });
    console.log(hasNegativeNumbers); // true
    ```

    `every`:
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: does this item meet your criteria?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: `false` after the first item that failed to meet your criteria, else `true`
    - **note**: stops iterating once it receives a falsy value from your callback.
    - _example use case_:
    ```js
    const allPositiveNumbers = [1, 2, 3].every(function (item) {
    return item > 0;
    });
    console.log(allPositiveNumbers); // true
    ```

    `find`:
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: is this item what you’re looking for?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: the item you’re looking for, or undefined
    - **note**: stops iterating once it receives a truthy value from your callback.
    - _example use case_:
    ```js
    const objects = [{ id: 'a' }, { id: 'b' }, { id: 'c' }];
    const found = objects.find(function (item) {
    return item.id === 'b';
    });
    console.log(found === objects[1]); // true
    ```

    `findIndex`:
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: is this item what you’re looking for?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: the index of the item you’re looking for, or `-1`
    - **note**: stops iterating once it receives a truthy value from your callback.
    - **note**: stops iterating once it receives a truthy value from your callback.
    - _example use case_:
    ```js
    const objects = [{ id: 'a' }, { id: 'b' }, { id: 'c' }];
    const foundIndex = objects.find(function (item) {
    return item.id === 'b';
    });
    console.log(foundIndex === 1); // true
    ```
  5. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ Below are some of the methods that *iterate* - in other words, that operate on t

    `reduce`:
    - _callback answers_: here’s the result from the previous iteration. what should i pass to the next iteration?
    - _callback gets these arguments: `result`, `item`, `index`, `list`
    - _callback gets these arguments_: `result`, `item`, `index`, `list`
    - _final return value_: result of last iteration

    `reduceRight`: (same as `reduce`, but in reversed order: last-to-first)
  6. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@ JavaScript Arrays have lots of built in methods on their prototype. Some of them

    Below are some of the methods that *iterate* - in other words, that operate on the entire list, one item at a time. When you call them, you provide a *callback function* - a single function that expects to operate on one item at a time. Based on the Array method you've chosen, the callback gets specific arguments, and may be expected to return a certain kind of value - and (except for `forEach`) the return value determines the final return value of the overarching array operation. Although most of the methods are guaranteed to execute for *each* item in the array - for all of them - some of the methods can stop iterating partway through; when applicable, this is indicated below.

    -------

    `forEach`:
    - _callback answers_: here’s an item. do something nutty with it, i don't care what.
    - _callback gets these arguments_: `item`, `index`, `list`
  7. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 38 additions and 29 deletions.
    67 changes: 38 additions & 29 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -1,48 +1,57 @@
    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    ## Intro
    JavaScript Arrays have lots of built in methods on their prototype. Some of them *mutate* - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. This means, to perform a single operation on the list as a whole ("atomically"), and to return a *new* list - thus making it much simpler to think about both the old list and the new one, what they contain, and what happened during the operation.

    Below are some of the methods that *iterate* - in other words, that operate on the entire list, one item at a time. When you call them, you provide a *callback function* - a single function that expects to operate on one item at a time. Based on the Array method you've chosen, the callback gets specific arguments, and may be expected to return a certain kind of value - and (except for `forEach`) the return value determines the final return value of the overarching array operation. Although most of the methods are guaranteed to execute for *each* item in the array - for all of them - some of the methods can stop iterating partway through; when applicable, this is indicated below.

    `forEach`:
    - callback answers: here’s an item. do something nutty with it, i don't care what.
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: nothing - in other words, `undefined`
    - _callback answers_: here’s an item. do something nutty with it, i don't care what.
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: nothing - in other words, `undefined`

    `map`:
    - callback answers: here’s an item. what should i put in the new list in its place?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of new items
    - _callback answers_: here’s an item. what should i put in the new list in its place?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: list of new items

    `filter`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: should i keep this item?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of kept items
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: should i keep this item?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: list of kept items

    `reduce`:
    - callback answers: here’s the result from the previous iteration. what should i pass to the next iteration?
    - callback gets these arguments: `result`, `item`, `index`, `list`
    - final return value: result of last iteration
    - _callback answers_: here’s the result from the previous iteration. what should i pass to the next iteration?
    - _callback gets these arguments: `result`, `item`, `index`, `list`
    - _final return value_: result of last iteration

    `reduceRight`: (same as `reduce`, but in reversed order: last-to-first)

    `some`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `true` after the first item that meets your criteria, else `false`
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: does this item meet your criteria?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: `true` after the first item that meets your criteria, else `false`
    - **note**: stops iterating once it receives a truthy value from your callback.

    `every`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `false` after the first item that failed to meet your criteria, else `true`
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: does this item meet your criteria?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: `false` after the first item that failed to meet your criteria, else `true`
    - **note**: stops iterating once it receives a falsy value from your callback.

    `find`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the item you’re looking for, or undefined
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: is this item what you’re looking for?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: the item you’re looking for, or undefined
    - **note**: stops iterating once it receives a truthy value from your callback.

    `findIndex`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the index of the item you’re looking for, or `-1`
    - _callback is a predicate_ - it should return a truthy or falsy value
    - _callback answers_: is this item what you’re looking for?
    - _callback gets these arguments_: `item`, `index`, `list`
    - _final return value_: the index of the item you’re looking for, or `-1`
    - **note**: stops iterating once it receives a truthy value from your callback.
  8. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ While attempting to explain JavaScript's `reduce` method on arrays, conceptually
    - final return value: nothing - in other words, `undefined`

    `map`:
    - callback answers: here’s an item. what should i replace it with?
    - callback answers: here’s an item. what should i put in the new list in its place?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of new items

  9. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 46 additions and 13 deletions.
    59 changes: 46 additions & 13 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,48 @@
    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    | method name | callback is a predicate? | what does the callback answer? | what arguments does the callback get? | what is the final return value? |
    |-|-|-|-|-|
    | `forEach` | no | here’s an item. do something nutty with it, i don't care what. | `item`, `index`, `list` | nothing - in other words, `undefined` |
    | `map` | no | here’s an item. what should i replace it with? | `item`, `index`, `list` | list of new items |
    | `filter` | yes | should i keep this item? | `item`, `index`, `list` | list of kept items |
    | `reduce` | no | here’s the result from the previous iteration. what should i pass to the next iteration? | `result`, `item`, `index`, `list` | result of last iteration |
    | `reduceRight` | no | (same as `reduce`, but in reversed order: last-to-first) |
    | `some` | yes | does this item meet your criteria? | `item`, `index`, `list` | `true` after the first item that meets your criteria, else `false` |
    | `every` | yes | does this item meet your criteria? | `item`, `index`, `list` | `false` after the first item that failed to meet your criteria, else `true` |
    | `find` | yes | is this item what you’re looking for? | `item`, `index`, `list` | the item you’re looking for, or undefined |
    | `findIndex` | yes | is this item what you’re looking for? | `item`, `index`, `list` | the index of the item you’re looking for, or `-1` |

    * note: a "predicate" is a function that returns a boolean - ie, `true` or `false`. (technically it will accept any truthy or falsy value, and effectively coerce it to a boolean for you)
    `forEach`:
    - callback answers: here’s an item. do something nutty with it, i don't care what.
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: nothing - in other words, `undefined`

    `map`:
    - callback answers: here’s an item. what should i replace it with?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of new items

    `filter`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: should i keep this item?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of kept items

    `reduce`:
    - callback answers: here’s the result from the previous iteration. what should i pass to the next iteration?
    - callback gets these arguments: `result`, `item`, `index`, `list`
    - final return value: result of last iteration

    `reduceRight`: (same as `reduce`, but in reversed order: last-to-first)

    `some`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `true` after the first item that meets your criteria, else `false`

    `every`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `false` after the first item that failed to meet your criteria, else `true`

    `find`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the item you’re looking for, or undefined

    `findIndex`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the index of the item you’re looking for, or `-1`
  10. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    | method name | callback is a predicate? | what does the callback answer? | what arguments does the callback get? | what is the final return value? |
    | - | - | - | - | - |
    |-|-|-|-|-|
    | `forEach` | no | here’s an item. do something nutty with it, i don't care what. | `item`, `index`, `list` | nothing - in other words, `undefined` |
    | `map` | no | here’s an item. what should i replace it with? | `item`, `index`, `list` | list of new items |
    | `filter` | yes | should i keep this item? | `item`, `index`, `list` | list of kept items |
  11. @ljharb ljharb revised this gist Dec 20, 2016. 1 changed file with 13 additions and 46 deletions.
    59 changes: 13 additions & 46 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -1,48 +1,15 @@
    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    `forEach`:
    - callback answers: here’s an item. do something nutty with it, i don't care what.
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: nothing - in other words, `undefined`

    `map`:
    - callback answers: here’s an item. what should i replace it with?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of new items

    `filter`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: should i keep this item?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of kept items

    `reduce`:
    - callback answers: here’s the result from the previous iteration. what should i pass to the next iteration?
    - callback gets these arguments: `result`, `item`, `index`, `list`
    - final return value: result of last iteration

    `reduceRight`: (same as `reduce`, but in reversed order: last-to-first)

    `some`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `true` after the first item that meets your criteria, else `false`

    `every`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `false` after the first item that failed to meet your criteria, else `true`

    `find`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the item you’re looking for, or undefined

    `findIndex`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the index of the item you’re looking for, or `-1`
    | method name | callback is a predicate? | what does the callback answer? | what arguments does the callback get? | what is the final return value? |
    | - | - | - | - | - |
    | `forEach` | no | here’s an item. do something nutty with it, i don't care what. | `item`, `index`, `list` | nothing - in other words, `undefined` |
    | `map` | no | here’s an item. what should i replace it with? | `item`, `index`, `list` | list of new items |
    | `filter` | yes | should i keep this item? | `item`, `index`, `list` | list of kept items |
    | `reduce` | no | here’s the result from the previous iteration. what should i pass to the next iteration? | `result`, `item`, `index`, `list` | result of last iteration |
    | `reduceRight` | no | (same as `reduce`, but in reversed order: last-to-first) |
    | `some` | yes | does this item meet your criteria? | `item`, `index`, `list` | `true` after the first item that meets your criteria, else `false` |
    | `every` | yes | does this item meet your criteria? | `item`, `index`, `list` | `false` after the first item that failed to meet your criteria, else `true` |
    | `find` | yes | is this item what you’re looking for? | `item`, `index`, `list` | the item you’re looking for, or undefined |
    | `findIndex` | yes | is this item what you’re looking for? | `item`, `index`, `list` | the index of the item you’re looking for, or `-1` |

    * note: a "predicate" is a function that returns a boolean - ie, `true` or `false`. (technically it will accept any truthy or falsy value, and effectively coerce it to a boolean for you)
  12. @ljharb ljharb created this gist Dec 20, 2016.
    48 changes: 48 additions & 0 deletions array_iteration_thoughts.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    While attempting to explain JavaScript's `reduce` method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

    `forEach`:
    - callback answers: here’s an item. do something nutty with it, i don't care what.
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: nothing - in other words, `undefined`

    `map`:
    - callback answers: here’s an item. what should i replace it with?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of new items

    `filter`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: should i keep this item?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: list of kept items

    `reduce`:
    - callback answers: here’s the result from the previous iteration. what should i pass to the next iteration?
    - callback gets these arguments: `result`, `item`, `index`, `list`
    - final return value: result of last iteration

    `reduceRight`: (same as `reduce`, but in reversed order: last-to-first)

    `some`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `true` after the first item that meets your criteria, else `false`

    `every`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: does this item meet your criteria?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: `false` after the first item that failed to meet your criteria, else `true`

    `find`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the item you’re looking for, or undefined

    `findIndex`:
    - callback is a predicate - it should return a truthy or falsy value
    - callback answers: is this item what you’re looking for?
    - callback gets these arguments: `item`, `index`, `list`
    - final return value: the index of the item you’re looking for, or `-1`