Composing with higher order functions

It's pretty obvious that composing by hand could easily be done in a similar fashion as we saw above with pipelining. For example, the unique word counting function that we wrote a couple of sections earlier, could be written in simple JS style:

const getUniqueWords1 = str => {    const str1 = removeNonAlpha(str);    const str2 = toUpperCase(str1);    const arr1 = splitInWords(str2);    const set1 = arrayToSet(arr1);    const arr2 = setToList(set1);    return arr2;};

Alternatively, it could be written more concisely (and more obscurely!) in one-liner style:

const getUniqueWords2 = str =>    setToList(arrayToSet(splitInWords(toUpperCase(removeNonAlpha(str)))));console.log(getUniqueWords2(GETTYSBURG_1_2));// [ 'A', 'AGO', 'ALL', ...

Get Mastering Javascript Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.