Split a character string based on change of character: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m →{{header|Perl 6}}: Remove stray parenthesis |
→JS ES6: updated groupBy primitive ( redrafted as a fold, rather than an explicit recursion with 'span' ) |
||
Line 178:
// groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
const groupBy = (f, xs) => {
const
.reduce((a, x) => {
const
h = a.active.length > 0 ? a.active[0] : undefined,
blnGroup = h !== undefined && f(h, x);
},
return dct.sofar.concat(dct.active.length > 0 ? [dct.active] : []);
▲ } else return [];
};
// intercalate :: String -> [a] -> String
const intercalate = (s, xs) => xs.join(s);
// TEST
|