Split a character string based on change of character: Difference between revisions

Content added Content deleted
(→‎JavaScript ES6: Added a variant expressed in terms of a general `span` function.)
Line 1,454: Line 1,454:
const i = xs.findIndex(x => !p(x));
const i = xs.findIndex(x => !p(x));


return -1 !== i ? (
return -1 !== i ? [
[xs.slice(0, i),
xs.slice(0, i),
xs.slice(i)
xs.slice(i)
]
] : [xs, []];
) : [xs, []];
};
};