I'm reading through a book that is discussing built in JavaScript functions compose() and pipe() for combining functions in functional style programming.
One of the examples seems to suggest running the following as front-end code:
const shuffle =
(deck, randomizer) => {
const doShuffle = pipe(
addRandom(randomizer),
sortByRandom,
map(card => card.card)
);
return doShuffle(deck);
};
But when I try running it in the Google Developer console I get back an error saying:
Uncaught ReferenceError: pipe is not defined
I've also tried in Firefox with the same results. What version of JavaScript is needed to make use of these functions?
Am I right to think these functions can only be used with node.js or some kind of pre-compiler like Babel?
Note: I'm running Ubuntu and have tried Chromium and Firefox.
pipeandcomposeare not native JavaScript functions. It sounds to me like you were reading a functional programming doc from a library like Ramda (ramdajs.com). Just include that library in your page, and your code will work.