Skip to content

Instantly share code, notes, and snippets.

@yckart
Last active August 29, 2015 14:07

Revisions

  1. yckart revised this gist Oct 17, 2014. 2 changed files with 11 additions and 11 deletions.
    16 changes: 8 additions & 8 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    ```javascript
    var array = [1, 2, 3, 4, 5, 6, 7, 8];
    var index = 0;
    var iterator = 0;

    console.log( array.slice(index, index += 1) ); // => [1]
    console.log( array.slice(index, index += 2) ); // => [2, 3]
    console.log( array.slice(index, index += 3) ); // => [4, 5, 6]
    console.log( array.slice(iterator, iterator += 1) ); // => [1]
    console.log( array.slice(iterator, iterator += 2) ); // => [2, 3]
    console.log( array.slice(iterator, iterator += 3) ); // => [4, 5, 6]
    ```

    The usage, with the utility-function below, is quite simple:

    ```javascript
    var steppable = stepArray([1, 2, 3, 4, 5, 6, 7, 8]);
    var step = stepArray([1, 2, 3, 4, 5, 6, 7, 8]);

    console.log( steppable(1) ); // => [1]
    console.log( steppable(2) ); // => [2, 3]
    console.log( steppable(3) ); // => [4, 5, 6]
    console.log( step(1) ); // => [1]
    console.log( step(2) ); // => [2, 3]
    console.log( step(3) ); // => [4, 5, 6]
    ```
    6 changes: 3 additions & 3 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    var stepArray = function (array) {
    var index = 0;
    return function (step) {
    return array.slice(index, index += step);
    var iterator = 0;
    return function (index) {
    return array.slice(iterator, iterator += index);
    };
    };
  2. yckart revised this gist Oct 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ console.log( array.slice(index, index += 2) ); // => [2, 3]
    console.log( array.slice(index, index += 3) ); // => [4, 5, 6]
    ```

    The usage with the utility-function below is quite simple:
    The usage, with the utility-function below, is quite simple:

    ```javascript
    var steppable = stepArray([1, 2, 3, 4, 5, 6, 7, 8]);
  3. yckart created this gist Oct 17, 2014.
    18 changes: 18 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    ```javascript
    var array = [1, 2, 3, 4, 5, 6, 7, 8];
    var index = 0;

    console.log( array.slice(index, index += 1) ); // => [1]
    console.log( array.slice(index, index += 2) ); // => [2, 3]
    console.log( array.slice(index, index += 3) ); // => [4, 5, 6]
    ```

    The usage with the utility-function below is quite simple:

    ```javascript
    var steppable = stepArray([1, 2, 3, 4, 5, 6, 7, 8]);

    console.log( steppable(1) ); // => [1]
    console.log( steppable(2) ); // => [2, 3]
    console.log( steppable(3) ); // => [4, 5, 6]
    ```
    6 changes: 6 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    var stepArray = function (array) {
    var index = 0;
    return function (step) {
    return array.slice(index, index += step);
    };
    };