Sha256: 7be5a719c57567d2b9711053b6f05968d4619ce20d9e0346939f38e89cb5b42d

Contents?: true

Size: 644 Bytes

Versions: 141

Compression:

Stored size: 644 Bytes

Contents

function List(list) {
  this.list = list || [];

  return {
    list: this.list,
    compare: function (other) {
      return {
        '-1': isSublist(other.list, this.list)
          ? 'SUBLIST'
          : 'UNEQUAL',
        '0': isSublist(other.list, this.list)
          ? 'EQUAL'
          : 'UNEQUAL',
        '1': isSublist(this.list, other.list)
          ? 'SUPERLIST'
          : 'UNEQUAL'
      }[lengthDiff(this, other)];
    }
  };
}

function lengthDiff(one, two) {
  return String(Math.sign(one.list.length - two.list.length));
}

function isSublist(one, two) {
  return one.join().match(two.join());
}


module.exports = List;

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.57 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.56 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.55 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.54 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.53 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.52 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.51 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.50 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.49 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.48 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.47 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.46 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.45 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.44 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.43 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.42 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.41 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.40 tracks/javascript/exercises/sublist/example.js
trackler-2.2.1.39 tracks/javascript/exercises/sublist/example.js