Split a character string based on change of character: Difference between revisions
Split a character string based on change of character (view source)
Revision as of 06:48, 14 October 2021
, 2 years ago→JS ES6
m (→JS ES6) |
m (→JS ES6) |
||
Line 1,247:
// group :: [a] -> [[a]]
const group = xs =>
// A list of lists, each containing only
// elements equal under (===), such that the
// concatenation of these lists is xs.
▲ const [h, ...t] = ys;
const [v, r] = t.reduce(
([gps, a], x) => x === a[0] ? (
Line 1,264 ⟶ 1,262:
return [...v, r];
})() : [];
// Tuple (,) :: a -> b -> (a, b)
|