Determine if a string has all unique characters: Difference between revisions
Determine if a string has all unique characters (view source)
Revision as of 22:53, 29 December 2019
, 4 years ago→{{header|JavaScript}}
Line 567:
const duplicatedCharIndices = s => {
const
groupBy(on(eq)(snd))(
sortBy(comparing(snd))(
Line 574:
)
);
return 0 <
) :
firstCase.map(fst)▼
));▼
};
Line 652 ⟶ 648:
// eq (==) :: Eq a => a -> a -> Bool
const eq = a => b => a === b;
// fanArrow (&&&) :: (a -> b) -> (a -> c) -> (a -> (b, c))
const fanArrow = f =>
// Compose a function from a simple value to a tuple of
// the separate outputs of two different functions.
g => x => Tuple(f(x))(g(x));
// filter :: (a -> Bool) -> [a] -> [a]
Line 702 ⟶ 704:
xs.length
) : Infinity;
// map :: (a -> b) -> [a] -> [b]
const map = f => xs =>
(Array.isArray(xs) ? (
// maybe :: b -> (a -> b) -> Maybe a -> b
|