In spreadsheet lesson, why chain arrow functions?

In the lesson to build your own spreadsheet, I don’t understand the functional purpose of chaining arrow functions:

const elemValue = num => character => idToText(character + num);
const addCharacters = character1 => character2 => num => charRange(character1, character2).map(elemValue(num));

This is introduces in step 46, but it is never explained why you would do this?

Why wouldn’t the above code just be:

const elemValue = (num, character) => idToText(character + num);
const addCharacters = (character1, character2, num) => charRange(character1, character2).map(elemValue(num));


To clarify: Array functions are a thing in PHP. Never heard of them in JavaScript. Do you mean arrow functions or array methods?

Hi Daniel! I corrected my description. I am interested in arrow functions.

The technique that’s demonstrated is actually called currying. It’s the process of taking functions with multiple arguments and turned them into a series of functions that each take a single argument. The goal is to cache expensive operations so we only have to do them once. The result can be then used in a lot of places.

Here’s more information about it: javascript - What is 'Currying'? - Stack Overflow

1 Like

Okaaaay. I read the article (thank you for the link). And I sort of see the point. But one of the main features is there is something about saving resources? Can you please explain how the example used in the lesson save resources? Is it in there only to get us accustomed to seeing it? It seems to me that it makes the code harder to understand because you are divorcing the arguments from the function.

In this particular lessons resources weren’t saved. This is to get accustomed to seeing it and being able to understand what’s going on.