Arguments Optional: with "currying" function

Hello,
Arguments Optional
I tried to use the “Currying”, but I did have success, is it possible ?

function addTogether(x, y) {
let array = []
array.push(x,y)
if (array.every(item => !Number.isInteger(item)&& array.length == 2)) {
  return undefined
} else if (array.every(item => Number.isInteger(item) && array.length == 2)) {
   return x + y
}
  else if (array.length == 1 && Number.isInteger(array[0])) {
  
  return function curry(x, y) { 
  return function(x) {
    return function(y) {
      return x + y;
    }
   } 
  }
 }
}
addTogether(2)(5);

You need to validate inputs in the case that you return a function.

I think you can make the curried function, but in the case that you get two valid inputs from the start, you’re going to need to call that curried function yourself.

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