Lodash object project pad method

in this exercice i try to write my code like this :






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






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

const _ = {
 

console.log(_.pad('bodreza', 12))
module.exports = _;

console.log(_.pad('bodreza', 12))
module.exports = _;

but when i try to execute my code i had this message in the console :
$ node test/pad.js
/home/ccuser/workspace/underscore-javascript-capstone/_.js:35
str = str.padStart(-length / 2, ’ ') + str.padEnd(length / 2, ’ ')
^

TypeError: str.padStart is not a function
at Object.pad (/home/ccuser/workspace/underscore-javascript-capstone/.js:35:15)
at Object. (/home/ccuser/workspace/underscore-javascript-capstone/
.js:46:15)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)

padStart() and padEnd() weren’t included until Node v8.0.0. The learning environment for that project is using Node v7.10.1, so you don’t have access to those methods.

Source: padStart Compatibility Chart

2 Likes

thank you very much my friend

another question, is my approach true for this method

There’s only one line of code in the error message, but that code would end up duplicating the string and doesn’t account for some of the parameters.

The code you posted but removed while I was responding was close, but didn’t deal with this part of the requirements:

Extra padding is added to the end of the string if an odd amount of padding is required to reach the specified length

Once you take care of that, then you’ll get all passing tests.

1 Like

i had anothe question please about this lodash object project can you help me to run the code of inRaange() method include in the (_) object this is his code :









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

const _ = {
  
inRange (number, start, end) {
  let aux = 0
   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


      


}
}

console.log(_.inRange(5, 7, 10))
module.exports = _;

it return me this kind of error :
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
$

Look very closely at the error message. It isn’t complaining about your code. It’s complaining that it can’t find a file named test/inRange.js. You must have run node test/inRange.js, but that isn’t the test’s name.

node test/in-range.js

As far as your code, you have an issue here:

The way it is written here, both start and end will become the original value of end. The value of start is lost

i have changed like this

aux = end
end = start
start = aux
but also it throw the self error

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.