Learn Functional Programming by Building a Spreadsheet - Step 74

Tell us what’s happening:

I found the correct solution less intuitive than my own and required seeing it to think of it. I understood the instructions as (Number, Period, Number), (Operator), (Number, Period, Number). The solution’s logic is (Number, Period)-repeat, (Operator), (Number, Period)-repeat - which allows for 1.2.3/1.2.3 as a match.

Could several solutions pass the test, or the instructions guide the user more to the desired regex term?

I got confused by the difference in function of capture groups () and character sets [ ]. I knew from the hints that I should use both, but I can only see character sets nested in capture groups working with the (Number, Period)-repeat design; maybe that’s a way to hint at the desired regex?

Your code so far

const highPrecedence = str => {
  const regex = /(\d+\.?\d+)([*/])(\d+\.?\d+)/

Your browser information:

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

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 74

Не могу пройти шаг 103

Step 103

Finally, to handle potential edge cases, add an empty string property (you will need to use quotes) which is a function that takes a single argument and returns that argument.

With that, your spreadsheet project is now complete. You are welcome to experiment with adding support for even more functions.

Break it down step-by-step:

  1. empty string as property “”
  2. is a function () => {}
  3. takes a single argument (arg)
  4. returns that argument => arg

I hope I didn’t just give the solution explicitly. Step 103 really is about interpreting the instructions as steps, the syntax is definitely known by you because you’ve gotten this far!

Please open a new topic for your question.

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Hi! I agree that the regex used in this lesson could use some more advanced logic and more thought overall. (Try to use the has2 formula in the spreadsheet – can you figure out why it fails but the code you provided passes? I’ve already submitted a github issue on it.) But I think the creators of the lesson are trying to balance simplicity for learning with the handling of all edge cases which could take quite a bit more logic.
The random and range formulas suffer similarly.

Apologies if you already understand capture group vs character sets, but:
a capture group allows us to work with that found group of text later on;
a character group limits the characters used in the pattern we are looking for.

So for your example regex code, the first and last capture groups would only recognize a number with 2 or more digits (e.g. 1.0, 33, 3.1415, 938.5, but not 2, 6, etc.). Can you figure out why?

I recommend the Regex Cheat Sheet: Regex Cheat Sheet

Hi, thank you for forwarding this to github. Yes, I assumed the creator implemented the simplest solution, and if the design is the student’s first intuition, it would be the simplest. However, I - and I assume others - got stuck figuring out why my functional design doesn’t pass, and what design is desired. I think trying to write the desired design is less motivating than writing a functional design (this also happens in steps prescribing implicitly returned functions, arrow function, etc optional syntax to pass).

I’d assume the tests for passing a step are regex-based if there are no functions to call, necessitating the “only-one-design-allowed” steps. In this case, I assume the best that can be done is adding several OR regex-based tests to cover more of the possible solutions for each step? For example, my solution OR the current one would pass.

Finally, I was quite confused why the spam filter project wasn’t before the spreadsheet project, as it teaches all the concepts (e.g., capture group vs character sets) comprehensively, whereas the spreadsheet project felt to presume knowledge of these (e.g., via a spam filter project primer) and was overall much more challenging.

Totally agree with you, I also was stuck on thinking why my solution wasn’t being accepted as the “correct” one doesn’t handle all the scenarios properly, for instance, it can match 123.123.123 as a number…which is obviously incorrect.

I believe this kind of things happen cause this curriculum is still in beta stage so a lot of improvements are yet to happen. The best thing we can do is actively contribute to the community either by posting this kind of questions on the forum, donate to the foundation or both :slight_smile: