In recreating Lodash library project, of web-development course, there is inRange method to be done. Part 7 of the ''Implement" instructions, says " After our second if statement, create a variable called isInRange and set it equal to a boolean expression that checks if start is smaller than or equal to number and if number is smaller than end .". I’ve tried to ommit the “create a variable” part, and simply return the boolean statement like this :
return (number >= start && number > end);
, but it didn’t work as expected. My question is why? Why do i have to create new variable for that boolean expression, and than return value of that variable?
In this project, there are already prepared test functions, which you are supposed to use after implementing a method in your code. I’m a little bit further now in this exercise, and not able to use the test for inRange again (permission denied). I also can’t recall, what were the errors precisely. My code right now looks like that:
if (end === undefined) {
end = start;
start = 0;
}
if (start > end) {
let tempEnd = end
end = start;
start = tempEnd;
}
let isInRange = number >= start && number < end;
return isInRange;
}
Before, when i tried to return the value directly, instead of using variable, it think it looked like that:
if (end === undefined) {
end = start;
start = 0;
}
if (start > end) {
let tempEnd = end
end = start;
start = tempEnd;
}
return (number >= start && number < end);
}
And that one above, returned few errors, when tested by ''test/in-range.js".
I get the feeling you’ve made multiple changes and ran the tests with a lot of time in-between.
You’d need to be able to run the test for one version, get a fail/success, then change to the other version, and get the other result, otherwise you can’t say that this change affects the outcome of the tests
Wow. Thank you ionatan. I feel now like a total dumbass… I should’ve better check it before asking a question. Anyways, good to know the answer!
Btw: What is the purpose of creating variable isInRange, if the code works exactly the same without it?