Permalink
Browse files

initial thing that seems to work

  • Loading branch information...
0 parents commit 0fc8e7e70aba2012b19c9db694c0d371a3283e6e @substack committed Jun 4, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 index.js
18 index.js
@@ -0,0 +1,18 @@
+module.exports = function (xs, ys) {
+ var res = [];
+ var i = 0, j = 0, k = 0;
+ for (; i < xs.length; i++) {
+ if (xs[i] === ys[j]) {
+ j++;
+ if (j === ys.length) {
+ res.push(xs.slice(k, i - j + 1));
+ j = 0;
+ k = i + 1;
+ }
+ }
+ else j = 0;
+ }
+
+ if (k < i) res.push(xs.slice(k, i));
+ return res;
+};

0 comments on commit 0fc8e7e

Please sign in to comment.