Why would the solution to this challenge declare a variable multiple times in the same script? Regardless of the scope this is absolutely terrible practice. This solutions should be offering best practices.
The two declarations of squaredIntegers are not the same variable. Rather, they are two variables with the same name.As you may recall from the scoping lessons, variables which are declared inside a function (using var, let, or const) exist only within that function.
He’s sort of right, that function is better off being a return ... one liner. If you insist on declaring a variable there then you are probably better off using a more descriptive function name and just calling the variable result or smth like that.
Has nothing to do with scope, just being consistent and descriptive with your naming conventions.
That’s why I specified “regardless of scope”. freecodecamp has a bad habit of taking challenges far outside the scope of the examples given. Throwing in identical variable names in different scopes adds to confusion. I think this challenge could definitely be re-written to more clearly illustrate the objective.
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => arr.filter( (num) => num > 0 && num % parseInt(num) === 0 ).map( (num) => Math.pow(num, 2) );
// test your code
console.log(squareList(realNumberArray));
Is the usage of “use script”; a byproduct of the testing platform? Because it’s been a very long time since I’ve seen anyone use that declaration in production code.
I understand , and I know that you have told me multiple times that they are updated in the github repository. I’m not proficient enough with github to navigate and find the updated code. I don’t think it should be expected of someone to check the repository to see if the code is different than what is provided in the solution. If that is the expectation could someone provide a short tutorial? I would love to be able to jump into the repository and contribute, but to be honest it’s a little daunting.