How could I make 1 function return 3 values so that those 3 values would serve as input parameters of another function (as if it were a callback --which in fact, I think it is--)?
So far I tried the following (although it did not work):
var resultado;
function num_2(repet){
for (var i = 0; i > repet-1; i++) {
if (i>=1) {
return i + ", ";
}else{
return i;
}
}
}
function sumarr(a,b,c){
if (a!="" && a!=null) {
resultado = a+b+c;
return "\n" + "resul: " + resultado + '\n' + "1: " +
a + '\n' + "2: " + b + '\n' + "3: " + c + '\n' + '\n';
}else{
return "noting";
}
}
console.log("\n" + "callback: " + sumarr(num_2(3)));
In javascript you can't, what you can do is return a structure that helps you with your task, for example you can return an array with the three elements or an object with three properties.
Example returning an array:
Example returning an object: