Change e letters to i in words: Difference between revisions
Content added Content deleted
Line 1,118: | Line 1,118: | ||
<lang javascript>(() => { |
<lang javascript>(() => { |
||
"use strict"; |
"use strict"; |
||
// ieTwins :: String -> [(String, String)] |
// ieTwins :: String -> [(String, String)] |
||
const ieTwins = s => { |
const ieTwins = s => { |
||
const |
const |
||
longWords = s.split("\n") |
|||
.filter(x => 5 < x.length), |
.filter(x => 5 < x.length), |
||
lexicon = new Set( |
lexicon = new Set( |
||
longWords.filter(w => w.includes("i")) |
|||
), |
), |
||
rgx = /e/gu; |
rgx = /e/gu; |
||
return |
return longWords.flatMap( |
||
w => w.includes("e") ? (() => { |
w => w.includes("e") ? (() => { |
||
const x = w.replace(rgx, "i"); |
const x = w.replace(rgx, "i"); |
||
return lexicon.has(x) ? [ |
return lexicon.has(x) ? [ |
||
[w, x] |
[w, x] |
||
Line 1,139: | Line 1,139: | ||
); |
); |
||
}; |
}; |
||
// ---------------------- TEST ----------------------- |
// ---------------------- TEST ----------------------- |
||
// main :: IO () |
// main :: IO () |
||
const main = () => { |
const main = () => { |
||
const s = readFile("unixdict.txt"); |
const s = readFile("unixdict.txt"); |
||
return ieTwins(s) |
return ieTwins(s) |
||
.map(JSON.stringify) |
.map(JSON.stringify) |
||
.join("\n"); |
.join("\n"); |
||
}; |
}; |
||
// --------------------- GENERIC --------------------- |
// --------------------- GENERIC --------------------- |
||
// readFile :: FilePath -> IO String |
// readFile :: FilePath -> IO String |
||
const readFile = fp => { |
const readFile = fp => { |
||
Line 1,164: | Line 1,164: | ||
e |
e |
||
); |
); |
||
return ObjC.unwrap( |
return ObjC.unwrap( |
||
ns.isNil() ? ( |
ns.isNil() ? ( |
||
Line 1,171: | Line 1,171: | ||
); |
); |
||
}; |
}; |
||
// MAIN --- |
// MAIN --- |
||
return main(); |
return main(); |