loading...

re: Solving "Arguments Optional" / freeCodeCamp Algorithm Challenges VIEW POST

FULL DISCUSSION
 

As you use Number.isInteger() , you'll miss float numbers.
You can use typeof / Object.prototype.toString.call() to detect number:

Number.isInteger(0.1)  // false
typeof 0.1 === "number"  // true
Object.prototype.toString.call(0.1) ==="[object Number]"  // true

And , here another solution:

const addTogether = ( a, ...arr ) =>
  typeof a !== "number" ? undefined
  : arr.length === 0 ? addT( a )
  : addT( a )( arr[0] )

const addT = a => b =>
  typeof b !== "number"  ? undefined
  : a + b
Code of Conduct Report abuse