Hello, to make this exercice work, it is important to store the value from my …args in a variable ?
I can’t use arrayArgs[0] and arrayArgs[1] ? i tried and it didn’t work.
So i did my firstValue and secondValue variable…
I just need clarification on this:
/*
Link: https://beta.freecodecamp.org/en/challenges/intermediate-algorithm-scripting/arguments-optional
*/
function addTogether( ...args ) {
const arrayArgs = [...args];
const firstValue = arrayArgs[0];
const secondValue = arrayArgs[1];
const arrayArgsL = arrayArgs.length;
if( ( arrayArgsL == 2 ) && ( Number.isInteger( firstValue ) == true ) && ( Number.isInteger( secondValue ) == true ) ) {
return firstValue + secondValue;
}else if( ( Number.isInteger( firstValue ) == false ) && ( Number.isInteger( secondValue ) == false ) ) {
return undefined;
}else if( arrayArgsL == 1 ) {
return function( b ) {
if( ( Number.isInteger( firstValue ) == true ) && ( Number.isInteger( b ) == true ) ) {
return firstValue + b;
}else {
return undefined;
}
};
}
};
console.log( addTogether( 2, 3 ) );
console.log( addTogether(2)(3) );
console.log( addTogether("http://bit.ly/IqT6zt") );
console.log( addTogether(2, "3") );
console.log( addTogether(2)([3]) );
Thx you !!
ps: If you have any idea concerning this exercice too:
https://forum.freecodecamp.org/t/need-help-smallest-common-multiple/161290/9