Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active March 8, 2016 11:06
Show Gist options
  • Save WebReflection/4327762cb87a8c634a29 to your computer and use it in GitHub Desktop.
Save WebReflection/4327762cb87a8c634a29 to your computer and use it in GitHub Desktop.

Revisions

  1. WebReflection revised this gist Mar 1, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion slice.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // Andrea Giammarchi, WTFPL
    function slice() {
    function slice() {'use strict';
    for (var
    o = +this, // offset
    i = o, // start index
  2. WebReflection created this gist Mar 1, 2015.
    21 changes: 21 additions & 0 deletions slice.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    // Andrea Giammarchi, WTFPL
    function slice() {
    for (var
    o = +this, // offset
    i = o, // start index
    l = arguments.length, // length
    n = l - o, // new length
    a = Array(n < 0 ? 0 : n); // new Array
    i < l; i++
    ) a[i - o] = arguments[i];
    return a;
    }

    /**
    * @example
    (function () {
    slice.apply(0, arguments); // [1,2,3]
    slice.apply(1, arguments); // [2,3]
    slice.apply(6, arguments); // []
    }(1,2,3));
    */