question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Avoid Mutations and Side Effects Using Functional Programming needs to validate the global variable is used in the incrementer function

See original GitHub issue

While reviewing a PR (#39363) that fixes a separate issue on the [Avoid Mutations and Side Effects Using Functional Programming](Avoid Mutations and Side Effects Using Functional Programming) challenge, I noticed the following test does not validate that the value returned from the incrementer function returns a value that is one larger than the fixedValue global variable’s value.

  - text: Your <code>incrementer</code> function should return a value that is one larger than the <code>fixedValue</code> value.
    testString: const newValue = incrementer(); assert(newValue === 5);

A user can simply write the following and pass the challenge without even using the fixedValue variable in the code.

var fixedValue = 4;

function incrementer () {
  // Only change code below this line
   return 5;
  // Only change code above this line
}

I suggest adding a third test, so that we set the value of fixedValue to a different value before calling the function. However, since the user could technically write const fixedValue = 4; instead of var fixedValue = 4;, one way of approaching this would be to use an IIFE: like the following:

  - text: Your <code>incrementer</code> function return a value based on the global `fixedValue` variable value.
    testString: |
      (function() {
       const fixedValue = 10;
       const newValue = incrementer();
       assert(fixedValue === 10 && newValue === 11);
      })()

Before adding a help wanted label, I am looking for feedback from others about this approach to fixing the challenge.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
arrohit258commented, Sep 1, 2020

Ok Thanks 🙂🙂

On Tue, Sep 1, 2020, 20:32 Nicholas Carrigan notifications@github.com wrote:

Heya @Rohit-Arora-0508 https://github.com/Rohit-Arora-0508

Thank you for your interest in contributing! There is currently an active PR that will close this issue, and it looks like that PR is on track for approval. We typically accept the first comprehensive PR that fixes an issue - as such, I would recommend looking for other issues labelled help wanted (or first timers only, if this is your first contribution) and check for ones that do not yet have a linked PR. 🙂

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/freeCodeCamp/freeCodeCamp/issues/39364#issuecomment-684920379, or unsubscribe https://github.com/notifications/unsubscribe-auth/APCTK7AX2LI6NCXRCQORZWLSDUEJVANCNFSM4PTZPOGQ .

1reaction
Mayank1795commented, Aug 8, 2020

@RandellDawson @Sky020 The call to incrementor function inside the IIFE does not refer to the fixedValue variable created inside IIFE. That’s why the assertion will give an error. te

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoiding Mutations and Side Effects Using Functional ...
It's easier to prevent bugs knowing that your functions don't change anything, including the function arguments or any global variable.
Read more >
Avoid Mutations and Side Effects Using Functional Programming
In this functional programming tutorial we avoid mutations and side effects using functional programming. This video constitutes one part of ...
Read more >
Avoid Mutations and Side Effects Using Functional
After my first reading, I said myself that the fact to put the global variable as argument protect the global variable of mutating....
Read more >
functional-programming - avoid-mutations-and-side-effects ...
Changes lead to bugs. It's easier to prevent bugs knowing that your functions don't change anything, including the function arguments or any ...
Read more >
Airbnb JavaScript Style Guide()
Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects. Use map() ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found