Learn Functional Programming by Building a Spreadsheet - Step 53

Tell us what’s happening:

I understand that the “.replace()” function should take a second argument, replacing what could be found by the RangeRegex, with something else.

But what would this be?

Specifically about this part of the code:

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, *(this is where I am lost)* ) 

}

I like this project, but sometimes it skips over so many vital information nuggets, that I am a bit lost.

Anyone has any tips to point me in the right direction?

My code so far

/* 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)];
}

const spreadsheetFunctions = {
  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, )

}

// User Editable Region


window.onload = () => {
  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('=')) {

  }
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 53

You’re correct, but the instructions don’t tell you what it should be.

In this case, follow the instructions exactly as described, and just have one argument. Often logic like this is broken into a few steps to make it easier. Unfortunately it can be a bit confusing since the logic isn’t complete yet.

Thank you for your answer! I feel so silly now :upside_down_face:

I tried to commit and save the code, and it worked :laughing: It felt very counter-intuative to commit “not correct” code.

It would be nice if the following code would also be accepted as an answer.

replace.(rangeRegex, )

ór, in previous steps often the instruction is “make an callback function but leave it empty for now”.
If in the instructions it would hint to the fact that this is not a working code, but something like “leave what to replace it with empty for now”, it would have been a lot clearer.

1 Like

Good suggestion, I would invite you to give feedback here:
https://github.com/freeCodeCamp/freeCodeCamp/issues