Browse Source

[fix] Fixed new Deck of single item causing empty Decks

master
Muthu Kumar 6 years ago
parent
commit
ff69d023cd
  1. 10
      structures/deck.js
  2. 8
      structures/slider.js

10
structures/deck.js

@ -1,10 +1,5 @@
class Deck extends Array {
constructor (...args) {
if(args.length === 1) return args;
return super(...args);
}
recurse (fn) {
let index = 0;
const call = (arr, acc = []) => {
@ -26,11 +21,6 @@ class Deck extends Array {
}
return -1;
}
empty () {
this.recurse(i => this.splice(i));
return this;
}
};
module.exports = Deck;

8
structures/slider.js

@ -17,8 +17,8 @@ class Slider {
const k = this.windowSize;
const host = new Deck(...master);
const guest = new Deck(...compare);
const host = Deck.from(master);
const guest = Deck.from(compare);
const startSliding = (window, i) => {
@ -30,13 +30,13 @@ class Slider {
)) !== -1
) return [ firstMatch, i ];
const newWindow = new Deck(...guest.slice(++i, k));
const newWindow = Deck.from(guest.slice(++i, k));
if(newWindow.length !== 0 && newWindow.length === k) return recurse(newWindow, i);
return [ -1, -1 ];
};
const window = new Deck(...guest.slice(0, k));
const window = Deck.from(guest.slice(0, k));
const index = startSliding(window, 0);
return index;
}

Loading…
Cancel
Save