Find words which contains more than 3 e vowels: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by one other user not shown)
Line 1,182:
 
 
---------- MORE THAN THREE VOWELS, AND NONE BUT E --------
 
p :: String -> Bool
Line 1,197:
main :: IO ()
main = readFile "unixdict.txt"
>>= (putStrLn . unlines . filter p . lines)</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>belvedere
Line 1,237 ⟶ 1,238:
 
(Also possible to do this with regular expressions, but this works. Here, we counted how many times each vowel occurred, limited the maximum count to 4, and checked the resulting signature.)
 
=={{header|JavaScript}}==
ECMAScript defines no file operations. Here, to read the dictionary, we use a library available to Apple's "JavaScript for Automation" embedding of a JS interpreter.
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
// ----- MORE THAN THREE VOWELS, AND NONE BUT E ------
 
// p :: String -> Bool
const p = w => {
// True if the word contains more than three vowels,
// and none of its vowels are other than "e".
const
[noOtherVowels, eCount] = [...w].reduce(
([bool, n], c) => bool
? "e" === c
? [bool, 1 + n]
: "aiou".includes(c)
? [false, n]
: [bool, n]
: [false, n],
 
// Initial accumulator.
[true, 0]
);
 
return noOtherVowels && (3 < eCount);
};
 
// ---------------------- TEST -----------------------
const main = () =>
lines(
readFile(
"~/Desktop/unixdict.txt"
)
)
.filter(p)
.join("\n");
 
// --------------------- GENERIC ---------------------
 
// lines :: String -> [String]
const lines = s =>
// A list of strings derived from a single string
// which is delimited by \n or by \r\n or \r.
0 < s.length
? s.split(/\r\n|\n|\r/u)
: [];
 
// ----------------------- jxa -----------------------
 
// readFile :: FilePath -> IO String
const readFile = fp => {
// The contents of a text file at the
// given file path.
const
e = $(),
ns = $.NSString
.stringWithContentsOfFileEncodingError(
$(fp).stringByStandardizingPath,
$.NSUTF8StringEncoding,
e
);
 
return ObjC.unwrap(
ns.isNil() ? (
e.localizedDescription
) : ns
);
};
 
// MAIN ---
return main();
})();</syntaxhighlight>
{{Out}}
<pre>belvedere
dereference
elsewhere
erlenmeyer
evergreen
everywhere
exegete
freewheel
nevertheless
persevere
preference
referee
seventeen
seventeenth
telemeter
tennessee</pre>
 
=={{header|jq}}==
Line 1,970 ⟶ 2,062:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./fmt" for Fmt
 
var hasAIOU = Fn.new { |word| word.any { |c| "aiou".contains(c) } }
9,485

edits