From 5b2dfa884bbe42fad3689aff23111954e4b7595a Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Sat, 12 May 2018 23:54:37 +0530 Subject: [PATCH] [fix] Fixed firstMatch condition and startSliding params --- lib/errorsHelper.js | 8 ++++---- lib/slideHelper.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/errorsHelper.js b/lib/errorsHelper.js index be12516..3403ffb 100644 --- a/lib/errorsHelper.js +++ b/lib/errorsHelper.js @@ -1,4 +1,4 @@ -const returnError = (code, message) => { +const createError = (code, message) => { return { err: message, code @@ -6,9 +6,9 @@ const returnError = (code, message) => { } const errors = { - 'WIN_TOO_LARGE_HOST': returnError('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'), - 'COULD_NOT_SLIDE': returnError('COULD_NOT_SLIDE', 'Could not slide into position for given window') + 'WIN_TOO_LARGE_HOST': createError('WIN_TOO_LARGE_HOST', 'Window size is larger than host object'), + 'WIN_TOO_LARGE_GUEST': createError('WIN_TOO_LARGE_GUEST', 'Window size is larger than guest object'), + 'COULD_NOT_SLIDE': createError('COULD_NOT_SLIDE', 'Could not slide into position for given window') }; module.exports = errors; \ No newline at end of file diff --git a/lib/slideHelper.js b/lib/slideHelper.js index b61fab7..1b5c72c 100644 --- a/lib/slideHelper.js +++ b/lib/slideHelper.js @@ -29,12 +29,12 @@ const startSliding = (k, predicate, host, guest, window, windowPos) => { const firstMatch = host.findIndex(wrap(test, window[0])); // 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); const nextWindowPos = windowPos + 1; 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;