Skip to content

Instantly share code, notes, and snippets.

@BouncingBison
Forked from ourmaninamsterdam/LICENSE
Created July 2, 2018 05:42
Show Gist options
  • Save BouncingBison/ed53b99ee0e2ce9db96242c712d2015a to your computer and use it in GitHub Desktop.
Save BouncingBison/ed53b99ee0e2ce9db96242c712d2015a to your computer and use it in GitHub Desktop.

Revisions

  1. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 20, 2015. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -26,12 +26,12 @@ This is a work-in-progress cheatsheet for JS arrays. Please feel free to leave a
    * [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)
    * [ES4 and below](#user-content-es4-and-below)
    * [ES5 and above](#user-content-es5-and-above)
    * [ES4 and below](#user-content-es4-and-below)
    * [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)
    * [ES4 and below](#user-content-es4-and-below-1)
    * [Randomise an array](#user-content-randomise-an-array)
    * [Chaining Methods](#chaining-methods)

    @@ -300,25 +300,25 @@ meals.filter(function(item) {
    ```
    ## Detect an array

    ### ES4 and below
    ### ES5 and above

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

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

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

    ### ES5 and above
    ### ES4 and below

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

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

    isArray(meals);
    // true
    ```

    @@ -341,6 +341,14 @@ meals.push('afternoon tea');

    ## Find index of an item

    ## ES5 and above

    ```javascript
    var meals = ['breakfast', 'elevenses', 'brunch'];
    meals.indexOf('brunch');
    // 2
    ```

    ### ES4 and below

    ```javascript
    @@ -366,14 +374,6 @@ inArray(meals, 'dinner');
    // -1
    ```

    ## ES5 and above

    ```javascript
    var meals = ['breakfast', 'elevenses', 'brunch'];
    meals.indexOf('brunch');
    // 2
    ```

    ## Randomise an array

    ```javascript
  2. @ourmaninamsterdam ourmaninamsterdam revised this gist Aug 20, 2015. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions arrayzing.md
    Original file line number Diff line number Diff line change
    @@ -43,6 +43,15 @@ var meals = ['breakfast', 'lunch', 'dinner'] ;

    ## Empty an array

    Keeping references intact.

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

    or

    ```javascript
    var meals = ['breakfast', 'lunch', 'dinner'];
    meals.length = 0
    @@ -168,7 +177,7 @@ meals;
    var meals = ['breakfast', 'lunch', 'dinner'];

    meals.splice(1, 2);
    // ['breakfast']
    // ['lunch', 'dinner']

    meals;
    // ['breakfast']
    @@ -338,16 +347,15 @@ meals.push('afternoon tea');
    var meals = ['breakfast', 'elevenses', 'brunch'];

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

    while(--i) {
    if(arr[i] === query){
    while(--i >= 0) {
    if(arr[i] === item){
    found = i;
    break;
    }
    }

    return found;
    }

  3. @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'];
  4. @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
    ```

  5. @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;
    }

  6. @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
  7. @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
  8. @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)
  9. @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
  10. @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;
  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,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)
  12. @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);
    }
    ]
    */
    ```
    ```
  13. @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)
  14. @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
  15. @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']
    ```

  16. @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
  17. @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

  18. @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]
    ```
  19. @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
  20. @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
  21. @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
    ```

  22. @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)
  23. @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)
  24. @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
  25. @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)
  26. @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

  27. @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'
    ```
  28. @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'
    ```
  29. @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
  30. @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)