Sha256: 86033e88bb24bca9db6d84a23dddfda1eb625bf4d2882fa761ef19c417e74d62

Contents?: true

Size: 629 Bytes

Versions: 396

Compression:

Stored size: 629 Bytes

Contents

export default class Series {

  constructor(numberString) {
    this.numberString = numberString;
    this.digits = this.getDigits();
  }

  getDigits() {
    return [...this.numberString].map(digit => parseInt(digit, 10));
  }

  slices(sliceSize) {
    const result = [];
    let slice = [];

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

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

    return result;
  }
}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.179 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.178 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.177 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.176 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.175 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.174 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.173 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.172 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.171 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.170 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.169 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.167 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.166 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.165 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.164 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.163 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.162 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.161 tracks/ecmascript/exercises/series/example.js
trackler-2.2.1.160 tracks/ecmascript/exercises/series/example.js