I'm new to coding and trying to figure out nested javascript functions. I've searched other questions but still can't figure it out. I'd like a function that takes a string of numbers seperated by spaces, converts the string to an array, and then outputs the result of a mathematical function on the array.
I've written something using the following outline and it works, but seems messy and don't know that I am really doing it the best way. I don't really understand how to call a function from another function.
function doMathOnThisString(string) {
var ar = convertStringToArray(string);
return doMathOnArray(ar);
function convertStringToArray(string) {
//code that converts the original input string to an array
return (ar)
};
function doMathOnArray(a) {
//code that does math on an array
};
}
return (ar)to return the result of the function.var result = string.split(' ').reduce((a,v)=> a * v);math function goes inside the "reduce"...see details on how reduce works here