From e5489b51a8c3d10e59aebeb9cc10bc842c886012 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 22 Aug 2018 17:35:19 +0300 Subject: [PATCH] working on .filter(path)... Signed-off-by: Alex A. Naanou --- diff.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/diff.js b/diff.js index a7defc0..dfd4abd 100644 --- a/diff.js +++ b/diff.js @@ -2133,6 +2133,7 @@ var DiffPrototype = { // path filter (non-function)... if(!(filter instanceof Function)){ + // normalize path... // format: // [ // '**' | [ .. ], @@ -2152,6 +2153,7 @@ var DiffPrototype = { : res[n].push(e) return res }, []) + // min length... var min = path .reduce(function(l, e){ @@ -2161,17 +2163,22 @@ var DiffPrototype = { var test = function(p, pattern, path){ return p == '**' ? // compare next pattern section and path... - cmp(pattern[0], path.slice(0, next.length)) - // shift path and test... - // XXX need to stop if we run put of path... - || (test(p, - pattern, - path.slice(1)) - // shift to next pattern section... - // XXX need to stop if we run put of pattern... - && test(pattern[1], - pattern.slice(2), - path.slice(pattern[0].length))) + (cmp(pattern[0], path.slice(0, next.length)) + // next pattern/path section + // XXX need to stop if we run put of path or pattern... + && test(pattern[1], + pattern.slice(2), + path.slice(next.length))) + // shift path and test... + // XXX need to stop if we run put of path... + || (test(p, + pattern, + path.slice(1)) + // shift to next pattern section... + // XXX need to stop if we run put of pattern... + && test(pattern[1], + pattern.slice(2), + path.slice(pattern[0].length))) : cmp(pattern[0], path) }