# Learn Functional Programming by Building a Spreadsheet - Step 62

### Tell us what’s happening:

Update your callback function to return the result of calling `idToText()` with `match` as the argument. Remember that your regular expression is case-insensitive, so you will need to call `toUpperCase()` on `match` before passing it to `idToText()` .

In a replace method we only have to pass two arguments, is it possible to add toUpperCase()to match before we add the function idToText ? like: replace(replace, match.toUpperCase, replacer function() ?

``````<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<body>
<div id="container">
<div></div>
</div>
<script src="./script.js"></script>
</body>
</html>
``````
``````/* file: styles.css */
#container {
display: grid;
grid-template-columns: 50px repeat(10, 200px);
grid-template-rows: repeat(11, 30px);
}

.label {
background-color: lightgray;
text-align: center;
vertical-align: middle;
line-height: 30px;
}
``````
``````/* file: script.js */
const isEven = num => num % 2 === 0;
const sum = nums => nums.reduce((acc, el) => acc + el, 0);
const average = nums => sum(nums) / nums.length;

const median = nums => {
const sorted = nums.slice().sort((a, b) => a - b);
const length = sorted.length;
const middle = length / 2 - 1;
return isEven(length)
? average([sorted[middle], sorted[middle + 1]])
: sorted[Math.ceil(middle)];
}

sum,
average,
median
}

const range = (start, end) => Array(end - start + 1).fill(start).map((element, index) => element + index);
const charRange = (start, end) => range(start.charCodeAt(0), end.charCodeAt(0)).map(code => String.fromCharCode(code));

/* User Editable Region */

const evalFormula = (x, cells) => {
const idToText = id => cells.find(cell => cell.id === id).value;
const rangeRegex = /([A-J])([1-9][0-9]?):([A-J])([1-9][0-9]?)/gi;
const rangeFromString = (num1, num2) => range(parseInt(num1), parseInt(num2));
const elemValue = num => character => idToText(character + num);
const addCharacters = character1 => character2 => num => charRange(character1, character2).map(elemValue(num));
const rangeExpanded = x.replace(rangeRegex, (_match, char1, num1, char2, num2) => rangeFromString(num1, num2).map(addCharacters(char1)(char2)));
const cellRegex = /[A-J][1-9][0-9]?/gi;
const cellExpanded = rangeExpanded.replace(cellRegex, idToText(match.toUpperCase())
);
}

/* User Editable Region */

const container = document.getElementById("container");
const createLabel = (name) => {
const label = document.createElement("div");
label.className = "label";
label.textContent = name;
container.appendChild(label);
}
const letters = charRange("A", "J");
letters.forEach(createLabel);
range(1, 99).forEach(number => {
createLabel(number);
letters.forEach(letter => {
const input = document.createElement("input");
input.type = "text";
input.id = letter + number;
input.ariaLabel = letter + number;
input.onchange = update;
container.appendChild(input);
})
})
}

const update = event => {
const element = event.target;
const value = element.value.replace(/\s/g, "");
if (!value.includes(element.id) && value.startsWith('=')) {

}
}
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`

### Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 62

1 Like

You need to use () to call to uppercase(), but yeah, you can pass the return value of a function call into another function call.

1 Like

JeremyLt,

``````.replace( replace,
.toUpperCase() method,
replacer function()
);
``````

Deeply regretted, it didn’t work.

I’m confused here. Is this your exact code? I am not sure where the word ‘method’ came from? You don’t need to write them word ‘method’ to use a method.

This is almost how you call a method, but you forgot to put the () at the end

I was just trying to explain to you my code, of course I don’t put the word method. all I did is:

``````.replace(cellRegex,  (match.toUpperCase(), idToText(match))
);
``````

What’s this part? I don’t understand what it is doing.

``````  const cellExpanded = rangeExpanded.replace(cellRegex, match => {})
``````

This is the original code you need to update. The only thing that you should change is replacing the {} with ’ calling `idToText()` with `match` as the argument’. Don’t make any other changes. You need to keep the arrow function syntax there.

That’s the hint !!!. Understood that I need to call toUpperCase() on match before passing it to the function.

Right, but did you see this part of what I wrote? You deleted more than only the {} from the original code. What you have in your first post is close if you don’t delete more than the {}

2 Likes

JeremyLt,
Thanks for your help, it works

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.