Longest common prefix: Difference between revisions

Content added Content deleted
m (→‎JS ES6: Updated primitives and output.)
Line 1,901: Line 1,901:
// allSame :: [a] -> Bool
// allSame :: [a] -> Bool
const allSame = xs =>
const allSame = xs =>
// True if xs is empty, or every item in the
// tail of the list is identical to the head.
0 === xs.length || (() => {
0 === xs.length || (() => {
const x = xs[0];
const [h, ...t] = xs;


return xs.every(y => x === y);
return t.every(x => h === x);
})();
})();