my quesstion is that what is the purpose of returning the map method result ?? the purpose of the function is to multiply values and return the result the caller only require the result not the array thanks
The map method returns a new array, if it is being used in a function, you need to do something with the returned array.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
thanks much my first time…follow up question is why is it that if i don’t return the map method the result of the function call is undefined even if i return the result that is required?
this function returns a undefined i removed the return statement in the map method because i don’t need the array only the result of multiplier * element.
the name of the function is multiply that is the statement above i post it maps the array, the first element of the array is the multiplier of the preceding values.!
I try to remove the return statement in the thearg.map what happen is that the return value become undefined so i wonder… the caller only require the result of the multiplier * element … so why is it that when i removed the return statement in the thearg.map the return value is undefined? it goes like this thearg.map(function(element)){ return multiplier * element;}); } the output is undefined.
if you remove the return from inside multiply then multiply doesn’t have a return statement anymore, and if a function doesn’t have a return statement it returns undefined by default
but i return the product of multiplier and the element is that not enough? return multiplier * element; is this not enough ? the caller only require the the product of multiplier and element and not the whole array itself?
thank you very much.! what you mean to say is that the return statement of multiply function is also a function return thearg.map(function(element) and inside this function the values also needed to be return return multiplier * element;
i also try to remove the return statement inside the map method return thearg.map(function(element) { multiplier * element; the output is [undefined,undefined,undefined] i thought is that if your return the map function the values will go with it but i realize javascript is not negotiable you need to return everything thank so much for the patience … in answering my questions…