Find words with alternating vowels and consonants: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
→‎{{header|JavaScript}}: Added a JS draft.
Hout (talk | contribs)
→‎{{header|JavaScript}}: Abstracted out an inColumns function.
Line 653: Line 653:
matches = lines(
matches = lines(
readFile('unixdict.txt')
readFile('unixdict.txt')
).filter(isLongAlternator),
).filter(isLongAlternator);
w = maximum(matches.map(length));


return `${matches.length} matches:\n\n` + (
return `${matches.length} matches:\n\n` + (
unlines(
inColumns(4)(matches)
chunksOf(4)(
matches.map(justifyLeft(w)(' '))
).map(unwords)
)
);
);
};
};

// ------------------- FORMATTING --------------------

// inColumns :: Int -> [String] -> String
const inColumns = n =>
xs => {
const w = maximum(xs.map(length));
return unlines(
chunksOf(n)(
xs.map(justifyLeft(w)(' '))
).map(unwords)
)
};


// --------------------- GENERIC ---------------------
// --------------------- GENERIC ---------------------