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:43, 28 December 2019
, 4 years ago→{{header|Haskell}}: Updated the variant in terms of find
(→{{header|Haskell}}: Added a Haskell variant.) |
(→{{header|Haskell}}: Updated the variant in terms of find) |
||
Line 444:
Or perhaps, as an alternative to grouping, sorting, and zipping:
<lang haskell>import Data.List (
import Numeric (showHex)
import Data.Bool (bool)
Line 450:
duplicatedCharIndices :: String -> Maybe (Char, [Int])
duplicatedCharIndices xs = go (zip xs [0 ..])
where
go [] = Nothing
go [_] = Nothing
go
maybe (go xs) (\(x, j) -> Just (x, [i, j])) (find ((c ==) . fst) xs)
---------------------------TEST----------------------------
Line 475 ⟶ 477:
duplicatedCharIndices
["", ".", "abcABC", "XYZ ZYX", "1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"]
--------------------------DISPLAY--------------------------
|