Skip to content

Instantly share code, notes, and snippets.

@krisnod
Forked from ourmaninamsterdam/LICENSE
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save krisnod/7fd2f45061f986da8e71 to your computer and use it in GitHub Desktop.

Select an option

Save krisnod/7fd2f45061f986da8e71 to your computer and use it in GitHub Desktop.

Revisions

  1. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 16, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -71,7 +71,7 @@ Or

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];
    meals.slice(-1);
    meals.slice(-1)[0];
    // 'dinner'
    ```

    @@ -284,7 +284,7 @@ meals.forEach(function(currentValue, index, arr){
    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner', 'supper'];

    meals.filter(function() (item) {
    meals.filter(function(item) {
    return item !== 'breakfast';
    });
    // ['lunch', 'dinner', 'supper'];
  2. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ var meals = ['breakfast', 'lunch', 'dinner'] ;
    ## Empty an array

    ```javascript
    var meals = new Array('breakfast', 'lunch', 'dinner');
    var meals = ['breakfast', 'lunch', 'dinner'];
    meals.length = 0
    ```

  3. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 8, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ meals.length = 0
    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];

    var copy = meals.slice(0, meals.length);
    var copy = meals.slice();
    // ['breakfast', 'lunch', 'dinner']
    ```

    @@ -337,16 +337,17 @@ meals.push('afternoon tea');
    ```javascript
    var meals = ['breakfast', 'elevenses', 'brunch'];

    function inArray(arr, query){
    function inArray(arr, item){
    var found = -1,
    len = arr.length,
    i = 0;
    i = len;

    for(; i < len; i++){
    while(--i) {
    if(arr[i] === query){
    found = i;
    }
    }

    return found;
    }

  4. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 8, 2015. 1 changed file with 25 additions and 25 deletions.
    50 changes: 25 additions & 25 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,6 @@ This is a work-in-progress cheatsheet for JS arrays. Please feel free to leave a
    * [Remove single item at a specific index](#user-content-remove-single-item-at-a-specific-index)
    * [Remove several items](#user-content-remove-several-items)
    * [Reverse an array](#user-content-reverse-an-array)
    * [Randomise an array](#user-content-randomise-an-array)
    * [Delimit an array](#user-content-delimit-an-array)
    * [Sort in numerical order](#user-content-sort-in-numerical-order)
    * [Sort in alphabetical order](#user-content-sort-in-alphabetical-order)
    @@ -33,6 +32,7 @@ This is a work-in-progress cheatsheet for JS arrays. Please feel free to leave a
    * [Find index of an item](#user-content-find-index-of-an-item)
    * [ES4 and below](#user-content-es4-and-below-1)
    * [ES5 and above](#user-content-es5-and-above-1)
    * [Randomise an array](#user-content-randomise-an-array)
    * [Chaining Methods](#chaining-methods)

    ## Create an array
    @@ -183,30 +183,6 @@ meals.reverse();
    // ['dinner', 'lunch', 'breakfast'];
    ```

    ## Randomise an array

    ```javascript
    function randomiseArray(arr) {
    var buffer = [], start;

    for(var i = arr.length; i >= arr.length && i > 0;i--) {
    start = Math.floor(Math.random() * arr.length);
    buffer.push(arr.splice(start, 1)[0])
    };

    return buffer;
    }

    randomiseArray([0,1,2,3,4]);
    // [2,1,0,3,4]

    randomiseArray([0,1,2,3,4]);
    // [3,2,1,4,0]

    randomiseArray([0,1,2,3,4]);
    // [1,2,4,0,3]
    ```

    ## Delimit an array

    ```javascript
    @@ -389,6 +365,30 @@ meals.indexOf('brunch');
    // 2
    ```

    ## Randomise an array

    ```javascript
    function randomiseArray(arr) {
    var buffer = [], start;

    for(var i = arr.length; i >= arr.length && i > 0;i--) {
    start = Math.floor(Math.random() * arr.length);
    buffer.push(arr.splice(start, 1)[0])
    };

    return buffer;
    }

    randomiseArray([0,1,2,3,4]);
    // [2,1,0,3,4]

    randomiseArray([0,1,2,3,4]);
    // [3,2,1,4,0]

    randomiseArray([0,1,2,3,4]);
    // [1,2,4,0,3]
    ```

    # Chaining methods

    ```javascript
  5. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 8, 2015. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -41,12 +41,6 @@ This is a work-in-progress cheatsheet for JS arrays. Please feel free to leave a
    var meals = ['breakfast', 'lunch', 'dinner'] ;
    ```

    Or

    ```javascript
    var meals = new Array('breakfast', 'lunch', 'dinner');
    ```

    ## Empty an array

    ```javascript
  6. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 8, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,8 @@ This is a work-in-progress cheatsheet for JS arrays. Please feel free to leave a
    * [Reverse an array](#user-content-reverse-an-array)
    * [Randomise an array](#user-content-randomise-an-array)
    * [Delimit an array](#user-content-delimit-an-array)
    * [Sort in alphabetical/numerical order](#user-content-sort-in-alphabeticalnumerical-order)
    * [Sort in reverse alphabetical/numerical order](#user-content-sort-in-reverse-alphabeticalnumerical-order)
    * [Sort in numerical order](#user-content-sort-in-numerical-order)
    * [Sort in alphabetical order](#user-content-sort-in-alphabetical-order)
    * [Join two arrays together](#user-content-join-two-arrays-together)
    * [Copy specific item(s)](#user-content-copy-specific-items)
    * [Augment items within an array](#user-content-augment-items-within-an-array)
  7. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 8, 2015. 1 changed file with 9 additions and 13 deletions.
    22 changes: 9 additions & 13 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -223,29 +223,25 @@ meals.join(' AND ');
    // 'breakfast AND lunch AND dinner'
    ```

    ## Sort in alphabetical/numerical order
    ## Sort in alphabetical order

    ```javascript

    var meals = ['breakfast', 'lunch', 'dinner'];
    var meals = ['dinner', 'supper', 'breakfast', 'lunch'];

    meals.sort();
    // ['breakfast', 'dinner', 'lunch']
    // ['breakfast', 'dinner', 'lunch', 'supper']
    ```

    ## Sort in reverse alphabetical/numerical order
    ## Sort in numerical order

    ```javascript
    [0, 1, 2, 3, 4, 5, 6].sort(function(a, b) {
    return b > a;
    });
    // [6, 5, 4, 3, 2, 1, 0]
    ```
    var numbers = [1438,2605,794,3947,6241,11745,2585];

    Or
    ```javascript
    [0, 1, 2, 3, 4, 5, 6].sort().reverse();
    // [6, 5, 4, 3, 2, 1, 0]
    numbers.sort(function(a, b) {
    return a - b;
    });
    // [794,1438,2585,2605,3947,6241,11745]
    ```

    ## Join two arrays together
  8. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -87,7 +87,7 @@ meals.slice(-1);

    var meals = ['breakfast', 'lunch', 'dinner'];

    ['breakfast', 'lunch', 'dinner'].shift();
    meals.shift();
    // 'breakfast'

    meals;
  9. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Arrayzing - The JavaScript array cheatsheet

    This is a WIP cheatsheet to help those on get a little stuck when.
    This is a work-in-progress cheatsheet for JS arrays. Please feel free to leave a comment if this has helped you or you would like to suggest anything.

    * [Create an array](#user-content-create-an-array)
    * [Empty an array](#user-content-empty-an-array)
  10. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 2 changed files with 23 additions and 1 deletion.
    20 changes: 20 additions & 0 deletions LICENSE
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    The MIT License (MIT)

    Copyright (c) 2015 Justin Perry

    Permission is hereby granted, free of charge, to any person obtaining a copy of
    this software and associated documentation files (the "Software"), to deal in
    the Software without restriction, including without limitation the rights to
    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
    the Software, and to permit persons to whom the Software is furnished to do so,
    subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    4 changes: 3 additions & 1 deletion arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Arrayzing - The JavaScript array cheatsheet

    This is a WIP cheatsheet to help those on get a little stuck when.

    * [Create an array](#user-content-create-an-array)
    * [Empty an array](#user-content-empty-an-array)
    * [Clone an array](#user-content-clone-an-array)
    @@ -451,4 +453,4 @@ getMealsByMaxCalories(meals, 850, 2000);
    }
    ]
    */
    ```
    ```
  11. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Array Cheatsheet
    # Arrayzing - The JavaScript array cheatsheet

    * [Create an array](#user-content-create-an-array)
    * [Empty an array](#user-content-empty-an-array)
  12. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 8 additions and 12 deletions.
    20 changes: 8 additions & 12 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -191,28 +191,24 @@ meals.reverse();

    ```javascript
    function randomiseArray(arr) {
    if(Object.prototype.toString.call(arr) !== '[object Array]') return;

    var copy = arr.slice(0, arr.length),
    buffer = [],
    start;
    var buffer = [], start;

    for(var i = copy.length; i >= copy.length && i > 0;i--) {
    start = parseInt(Math.random() * copy.length, 16);
    buffer.push(copy.splice(start, 1)[0])
    for(var i = arr.length; i >= arr.length && i > 0;i--) {
    start = Math.floor(Math.random() * arr.length);
    buffer.push(arr.splice(start, 1)[0])
    };

    return buffer;
    }

    randomiseArray(arr);
    randomiseArray([0,1,2,3,4]);
    // [2,1,0,3,4]

    randomiseArray(arr);
    randomiseArray([0,1,2,3,4]);
    // [3,2,1,4,0]

    randomiseArray(arr);
    // [1,2,4,0,2]
    randomiseArray([0,1,2,3,4]);
    // [1,2,4,0,3]
    ```

    ## Delimit an array
  13. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -58,8 +58,6 @@ meals.length = 0
    var meals = ['breakfast', 'lunch', 'dinner'];

    var copy = meals.slice(0, meals.length);

    copy;
    // ['breakfast', 'lunch', 'dinner']
    ```

  14. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -52,6 +52,17 @@ var meals = new Array('breakfast', 'lunch', 'dinner');
    meals.length = 0
    ```

    ## Clone an array

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];

    var copy = meals.slice(0, meals.length);

    copy;
    // ['breakfast', 'lunch', 'dinner']
    ```

    ## Get last item

    ```javascript
  15. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    # Array Cheatsheet

    * [Create an array](#user-content-creating-an-array)
    * [Create an array](#user-content-create-an-array)
    * [Empty an array](#user-content-empty-an-array)
    * [Get last item](#user-content-getting-last-item)
    * [Clone an array](#user-content-clone-an-array)
    * [Get last item](#user-content-get-last-item)
    * [Remove first item](#user-content-remove-first-item)
    * [Remove last item](#user-content-remove-last-item)
    * [Add new item(s) to beginning](#user-content-add-new-items-to-beginning)
    @@ -32,7 +33,7 @@
    * [ES5 and above](#user-content-es5-and-above-1)
    * [Chaining Methods](#chaining-methods)

    ## Creating an array
    ## Create an array

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'] ;
    @@ -51,7 +52,7 @@ var meals = new Array('breakfast', 'lunch', 'dinner');
    meals.length = 0
    ```

    ## Getting last item
    ## Get last item

    ```javascript

  16. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -197,8 +197,10 @@ function randomiseArray(arr) {

    randomiseArray(arr);
    // [2,1,0,3,4]

    randomiseArray(arr);
    // [3,2,1,4,0]

    randomiseArray(arr);
    // [1,2,4,0,2]
    ```
  17. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 17 additions and 4 deletions.
    21 changes: 17 additions & 4 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -181,13 +181,26 @@ meals.reverse();

    ```javascript
    function randomiseArray(arr) {
    var buffer = [], start;
    for(var i = arr.length; i >= arr.length && i > 0;i--) {
    start = parseInt(Math.random() * arr.length, 16);
    buffer.push(arr.splice(start,1)[0])
    if(Object.prototype.toString.call(arr) !== '[object Array]') return;

    var copy = arr.slice(0, arr.length),
    buffer = [],
    start;

    for(var i = copy.length; i >= copy.length && i > 0;i--) {
    start = parseInt(Math.random() * copy.length, 16);
    buffer.push(copy.splice(start, 1)[0])
    };

    return buffer;
    }

    randomiseArray(arr);
    // [2,1,0,3,4]
    randomiseArray(arr);
    // [3,2,1,4,0]
    randomiseArray(arr);
    // [1,2,4,0,2]
    ```

    ## Delimit an array
  18. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 6, 2015. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@
    * [Remove single item at a specific index](#user-content-remove-single-item-at-a-specific-index)
    * [Remove several items](#user-content-remove-several-items)
    * [Reverse an array](#user-content-reverse-an-array)
    * [Randomise an array](#user-content-randomise-an-array)
    * [Delimit an array](#user-content-delimit-an-array)
    * [Sort in alphabetical/numerical order](#user-content-sort-in-alphabeticalnumerical-order)
    * [Sort in reverse alphabetical/numerical order](#user-content-sort-in-reverse-alphabeticalnumerical-order)
    @@ -176,6 +177,19 @@ meals.reverse();
    // ['dinner', 'lunch', 'breakfast'];
    ```

    ## Randomise an array

    ```javascript
    function randomiseArray(arr) {
    var buffer = [], start;
    for(var i = arr.length; i >= arr.length && i > 0;i--) {
    start = parseInt(Math.random() * arr.length, 16);
    buffer.push(arr.splice(start,1)[0])
    };
    return buffer;
    }
    ```

    ## Delimit an array

    ```javascript
  19. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 4, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -296,6 +296,8 @@ var meals = ['breakfast', 'lunch', 'dinner'];
    function isArray(arr) {
    return !!(Object.prototype.toString.call(arr) === '[object Array]');
    }

    isArray(meals);
    // true
    ```

  20. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 3, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@
    * [Get last item](#user-content-getting-last-item)
    * [Remove first item](#user-content-remove-first-item)
    * [Remove last item](#user-content-remove-last-item)
    * [Add new item(s) to beginning](#user-content-add-new-item-to-beginning)
    * [Add new item(s) to end](#user-content-add-new-item-to-end)
    * [Add new item(s) to beginning](#user-content-add-new-items-to-beginning)
    * [Add new item(s) to end](#user-content-add-new-items-to-end)
    * [Overwrite item at a specific index](#user-content-overwrite-item-at-a-specific-index)
    * [Add new item(s) at a specific index](#user-content-add-new-items-at-a-specific-index)
    * [Remove single item at a specific index](#user-content-remove-single-item-at-a-specific-index)
  21. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 3, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@
    * [Get last item](#user-content-getting-last-item)
    * [Remove first item](#user-content-remove-first-item)
    * [Remove last item](#user-content-remove-last-item)
    * [Add new item to beginning](#user-content-add-new-item-to-beginning)
    * [Add new item to end](#user-content-add-new-item-to-end)
    * [Add new item(s) to beginning](#user-content-add-new-item-to-beginning)
    * [Add new item(s) to end](#user-content-add-new-item-to-end)
    * [Overwrite item at a specific index](#user-content-overwrite-item-at-a-specific-index)
    * [Add new item(s) at a specific index](#user-content-add-new-items-at-a-specific-index)
    * [Remove single item at a specific index](#user-content-remove-single-item-at-a-specific-index)
  22. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 3, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -23,10 +23,12 @@
    * [Execute a function once per array item](#user-content-execute-a-function-once-per-array-item)
    * [Filter an array](#user-content-filter-an-array)
    * [Detect an array](#user-content-detect-an-array)
    * [Simple FIFO queue](#user-content-simple-fifo-queue)
    * [Find index of an item](#user-content-find-index-of-an-item)
    * [ES4 and below](#user-content-es4-and-below)
    * [ES5 and above](#user-content-es5-and-above)
    * [Simple FIFO queue](#user-content-simple-fifo-queue)
    * [Find index of an item](#user-content-find-index-of-an-item)
    * [ES4 and below](#user-content-es4-and-below-1)
    * [ES5 and above](#user-content-es5-and-above-1)
    * [Chaining Methods](#chaining-methods)

    ## Creating an array
  23. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 3, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    * [Return true if at least one item matches a condition](#user-content-return-true-if-at-least-one-item-matches-a-condition)
    * [Execute a function once per array item](#user-content-execute-a-function-once-per-array-item)
    * [Filter an array](#user-content-filter-an-array)
    * [Detect an array[(#user-content-detect-an-array)
    * [Detect an array](#user-content-detect-an-array)
    * [Simple FIFO queue](#user-content-simple-fifo-queue)
    * [Find index of an item](#user-content-find-index-of-an-item)
    * [ES4 and below](#user-content-es4-and-below)
  24. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 3, 2015. 1 changed file with 25 additions and 2 deletions.
    27 changes: 25 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,7 @@
    * [Return true if at least one item matches a condition](#user-content-return-true-if-at-least-one-item-matches-a-condition)
    * [Execute a function once per array item](#user-content-execute-a-function-once-per-array-item)
    * [Filter an array](#user-content-filter-an-array)
    * [Detect an array[(#user-content-detect-an-array)
    * [Simple FIFO queue](#user-content-simple-fifo-queue)
    * [Find index of an item](#user-content-find-index-of-an-item)
    * [ES4 and below](#user-content-es4-and-below)
    @@ -90,7 +91,7 @@ meals;
    // ['breakfast', 'lunch'];
    ```

    ## Add new item to beginning
    ## Add new item(s) to beginning

    ```javascript
    var meals = ['lunch', 'dinner'];
    @@ -102,7 +103,7 @@ meals;
    // ['breakfast', 'lunch', 'dinner']
    ```

    ## Add new item to end
    ## Add new item(s) to end

    ```javascript

    @@ -267,6 +268,7 @@ meals.some(function(item){ return item === 'burgers!!';});

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner', 'supper'];

    meals.forEach(function(currentValue, index, arr){
    console.log(index, currentValue, arr);
    });
    @@ -282,6 +284,27 @@ meals.filter(function() (item) {
    });
    // ['lunch', 'dinner', 'supper'];
    ```
    ## Detect an array

    ### ES4 and below

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];

    function isArray(arr) {
    return !!(Object.prototype.toString.call(arr) === '[object Array]');
    }
    // true
    ```

    ### ES5 and above

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];

    Array.isArray(meals)
    // true
    ```

    ## Simple FIFO queue

  25. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 1, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -60,6 +60,7 @@ meals[meals.length - 1];
    Or

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];
    meals.slice(-1);
    // 'dinner'
    ```
  26. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 1, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,11 @@ var meals = ['breakfast', 'lunch', 'dinner'];

    meals[meals.length - 1];
    // 'dinner'
    ```

    Or

    ```javascript
    meals.slice(-1);
    // 'dinner'
    ```
  27. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 1, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # Array Cheatsheet

    * [Create an array](#user-content-creating-an-array)
    * [Empty an array](#user-content-empty-an-array)
    * [Get last item](#user-content-getting-last-item)
    * [Remove first item](#user-content-remove-first-item)
    * [Remove last item](#user-content-remove-last-item)
    @@ -39,6 +40,13 @@ Or
    var meals = new Array('breakfast', 'lunch', 'dinner');
    ```

    ## Empty an array

    ```javascript
    var meals = new Array('breakfast', 'lunch', 'dinner');
    meals.length = 0
    ```

    ## Getting last item

    ```javascript
  28. @ourmaninamsterdam ourmaninamsterdam revised this gist Jul 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Array Cheatsheet

    * [Creating an array](#user-content-creating-an-array)
    * [Getting last item](#user-content-getting-last-item)
    * [Create an array](#user-content-creating-an-array)
    * [Get last item](#user-content-getting-last-item)
    * [Remove first item](#user-content-remove-first-item)
    * [Remove last item](#user-content-remove-last-item)
    * [Add new item to beginning](#user-content-add-new-item-to-beginning)
  29. @ourmaninamsterdam ourmaninamsterdam revised this gist Jul 30, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    * [Execute a function once per array item](#user-content-execute-a-function-once-per-array-item)
    * [Filter an array](#user-content-filter-an-array)
    * [Simple FIFO queue](#user-content-simple-fifo-queue)
    * [Check if an item is in an array](#user-content-check-if-an-item-is-in-an-array)
    * [Find index of an item](#user-content-find-index-of-an-item)
    * [ES4 and below](#user-content-es4-and-below)
    * [ES5 and above](#user-content-es5-and-above)
    * [Chaining Methods](#chaining-methods)
    @@ -287,15 +287,15 @@ meals.push('afternoon tea');
    // ... and so on ...
    ```

    ## Check if an item is in an array
    ## Find index of an item

    ### ES4 and below

    ```javascript
    var meals = ['breakfast', 'elevenses', 'brunch'];

    function inArray(arr, query){
    var found = false,
    var found = -1,
    len = arr.length,
    i = 0;

    @@ -311,7 +311,7 @@ inArray(meals, 'brunch');
    // 2 - the index of the item in the array

    inArray(meals, 'dinner');
    // false
    // -1
    ```

    ## ES5 and above
  30. @ourmaninamsterdam ourmaninamsterdam revised this gist Jul 30, 2015. No changes.