Sha256: 6e185d1a3814269698dcc4cb4c530bf3cb98cf57216d3e9b919b8a01f676a015

Contents?: true

Size: 687 Bytes

Versions: 141

Compression:

Stored size: 687 Bytes

Contents

'use strict';

function Series(numberString) {
  this.numberString = numberString;
  this.digits = this.getDigits();
}

Series.prototype.getDigits = function () {
  return this.numberString.split('').map(function (digit) {
    return parseInt(digit, 10);
  });
};

Series.prototype.slices = function (sliceSize) {
  var result = [];
  var slice = [];

  if (sliceSize > this.digits.length) {
    throw new Error('Slice size is too big.');
  }

  for (var i = 0; i < this.digits.length - sliceSize + 1; i++) {
    for (var j = 0; j < sliceSize; j++) {
      slice.push(this.digits[i + j]);
    }
    result.push(slice);
    slice =  [];
  }

  return result;
};

module.exports = Series;

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/javascript/exercises/series/example.js
trackler-2.2.1.97 tracks/javascript/exercises/series/example.js
trackler-2.2.1.96 tracks/javascript/exercises/series/example.js
trackler-2.2.1.95 tracks/javascript/exercises/series/example.js
trackler-2.2.1.94 tracks/javascript/exercises/series/example.js
trackler-2.2.1.93 tracks/javascript/exercises/series/example.js
trackler-2.2.1.92 tracks/javascript/exercises/series/example.js
trackler-2.2.1.91 tracks/javascript/exercises/series/example.js
trackler-2.2.1.90 tracks/javascript/exercises/series/example.js
trackler-2.2.1.89 tracks/javascript/exercises/series/example.js
trackler-2.2.1.88 tracks/javascript/exercises/series/example.js
trackler-2.2.1.87 tracks/javascript/exercises/series/example.js
trackler-2.2.1.86 tracks/javascript/exercises/series/example.js
trackler-2.2.1.85 tracks/javascript/exercises/series/example.js
trackler-2.2.1.84 tracks/javascript/exercises/series/example.js
trackler-2.2.1.83 tracks/javascript/exercises/series/example.js
trackler-2.2.1.82 tracks/javascript/exercises/series/example.js
trackler-2.2.1.81 tracks/javascript/exercises/series/example.js
trackler-2.2.1.80 tracks/javascript/exercises/series/example.js
trackler-2.2.1.79 tracks/javascript/exercises/series/example.js