Browse Source

[fix] Fixed firstMatch condition and startSliding params

master
Muthu Kumar 7 years ago
parent
commit
5b2dfa884b
  1. 8
      lib/errorsHelper.js
  2. 4
      lib/slideHelper.js

8
lib/errorsHelper.js

@ -1,4 +1,4 @@
const returnError = (code, message) => { const createError = (code, message) => {
return { return {
err: message, err: message,
code code
@ -6,9 +6,9 @@ const returnError = (code, message) => {
} }
const errors = { const errors = {
'WIN_TOO_LARGE_HOST': returnError('WIN_TOO_LARGE_HOST', 'Window size is larger than host object'), 'WIN_TOO_LARGE_HOST': createError('WIN_TOO_LARGE_HOST', 'Window size is larger than host object'),
'WIN_TOO_LARGE_GUEST': returnError('WIN_TOO_LARGE_GUEST', 'Window size is larger than guest object'), 'WIN_TOO_LARGE_GUEST': createError('WIN_TOO_LARGE_GUEST', 'Window size is larger than guest object'),
'COULD_NOT_SLIDE': returnError('COULD_NOT_SLIDE', 'Could not slide into position for given window') 'COULD_NOT_SLIDE': createError('COULD_NOT_SLIDE', 'Could not slide into position for given window')
}; };
module.exports = errors; module.exports = errors;

4
lib/slideHelper.js

@ -29,12 +29,12 @@ const startSliding = (k, predicate, host, guest, window, windowPos) => {
const firstMatch = host.findIndex(wrap(test, window[0])); const firstMatch = host.findIndex(wrap(test, window[0]));
// If first item returns a match, then continue to slideNext() // If first item returns a match, then continue to slideNext()
const len = firstMatch ? slideNext(host, guest, firstMatch, windowPos) : undefined; const len = (firstMatch !== -1) ? slideNext(host, guest, firstMatch, windowPos) : undefined;
if (len && len > 1) return converter(firstMatch, windowPos, len); if (len && len > 1) return converter(firstMatch, windowPos, len);
const nextWindowPos = windowPos + 1; const nextWindowPos = windowPos + 1;
const newWindow = guest.slice(nextWindowPos, nextWindowPos + k); const newWindow = guest.slice(nextWindowPos, nextWindowPos + k);
if (newWindow.length === k) return startSliding(newWindow, nextWindowPos); if (newWindow.length === k) return startSliding(k, predicate, host, guest, newWindow, nextWindowPos);
return errors.COULD_NOT_SLIDE; return errors.COULD_NOT_SLIDE;

Loading…
Cancel
Save