Lodash object project

in the second method of object called “inRange” in the last step inside this method i declare a variable called isInRange like this but the code don’t run right in the terminal :






// Do not write or modify code below this line.

const _ = {
  clamp(number, lower, upper) {
let lowerClampedValue = Math.max(number, lower)
let clampedValue = Math.min(lowerClampedValue, upper)
return clampedValue
},
inRange (number, start, end) {
  let aux = 0
  if(end == undefined) {
    end = start
  start = 0
  
}
if(start > end){
  aux = start
  start = end
  end = aux
}
let isInRange = number > start && number < end
return isInRange

}

}
console.log(_.clamp(4, 5, 6))
console.log(_.inRange(3, 7, 6))
module.exports = _;

Remember to include the start value in the range.

but the start value is include in the range

But is it really included?

yes of corse sir the start value is included in range method






// Do not write or modify code below this line.

const _ = {
  clamp(number, lower, upper) {
let lowerClampedValue = Math.max(number, lower)
let clampedValue = Math.min(lowerClampedValue, upper)
return clampedValue
},
inRange (number, start, end) {
  let aux = 0
  else if(end == undefined) {
    end = start
  start = 0
  
}
else if(start > end){
  aux = end
  start = aux
  end = start
}
let isInRange =  number => start && number <= end
return isInRange

},
words(str) {
return str.split('')
},
pad(string, length) {
  
}

}

console.log(_.inRange(3, 8, 6))
module.exports = _;

but when i try to run my code this message appear tome in the console :
$ node test/inRange.js
module.js:472
throw err;
^

Error: Cannot find module ‘/home/ccuser/workspace/underscore-javascript-capstone/test/inRange.js’
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

Is the end value intended to be in the range?

I Had excluded the end value from the range but it the same thing happen also
“&& number < end” not “number <= end”

From this error message it appears that the test-script can’t be located. You should be able to look in the test directory to see the names of the test-files. My test-file is called in-range.js for this project so try to start the test with:

node test/in-range.js

2 Likes

THANK YOU A LOT SIR .It’s the solution