Arguments optional - exercise

My code is passing all the tests except the test when we pass just one argument

addTogether(“https://www.youtube.com/watch?v=dQw4w9WgXcQ”)

Here is my code

function addTogether()
{
  let somme = 0;
    somme=arguments[0] //somme=2
   // return (Number.isFinite(arguments[0]))
      
     if(Number.isFinite(arguments[0]) || (Number.isFinite(arguments[1])))//true
        if(arguments.length === 2)
        return somme+arguments[1]
        {
            if(arguments.length === 1) //false 
        {
         return function sum(a)
          
         { 
            if (a===undefined)
         return undefined 
         if (typeof(a)=="number") 
            {somme= somme+a
            return somme
            }
            
          if ((Number.isFinite(arguments[0])===false )||(Number.isFinite(a)===false)   )
            {
              return undefined
            }
         
                        
          }
           
        }
        }
         if(Number.isFinite(arguments[0] ===false) && Number.isFinite(arguments[1] === false))
              { 
                return undefined
              }    
        
            
       

            }
console.log(addTogether(2)(2))
console.log((addTogether("https://www.youtube.com/watch?v=dQw4w9WgXcQ")))

Well i tried to check for the presence of the argument a inside the sum function using an if statement and the following line

if (arguments.length===0) return undefined

when i removed the rest of the code inside sum() and and the keyword return before the function sum() it returned undefined ,Actually it s the first time i’m using closure but still don t figure out the difference between curried functions and closure

in the case of one argument, you don’t check that it’s valid, you just return a function

1 Like

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