The initial function seemed straightforward and very close to functional programming but there was a bit of buried complexity.
function generate(seedWords) {
const filteredWords = filterInputs(seedWords);
const initialHash = R.head(filteredWords) || 'thunder';
const hashWithRandom = appendRandom(initialHash);
return generateHelper(hashWithRandom, R.tail(filteredWords));
}
The rewrite is point-free and relies on ramda a lot. It isn't highly readable but I think thats because of familiarity with the library and with point free style. The code isn't difficult it's just a bit dense.
const generate = R.pipe(
filterInputs,
R.converge(
generateHelper,
[
R.pipe(
R.ifElse(
R.isEmpty,
R.head,
R.always('thunder')
),
appendRandom
),
R.identity
]
)
)