I've tried to figure this out for a couple of hours, but I don't see what I am doing or not doing to make this work. Any help is appreciated. I am getting 2 list of numbers from the user using the following html:
<input type = "text" id = "firstArray"><br/>
<input type = "text" id = "secondArray"><br>
I am then calling the function in my external js file (event handler works and function is called passing the 2 list of numbers):
Answer = largestNumbers(document.getElementById("firstArray").value,
document.getElementById("secondArray").value);
Then in my js function, I am attaching the 2 list of numbers to an array, making it 2 arrays inside an array. I am wanting to find the largest number of each array and send those 2 numbers to an array (largeList) and send the output to the console.log. Below is the js function:
function largestNumbers(arr, arr1) {
var otherArray = [];
var largeList = [];
otherArray[0] = arr.split(" ");
otherArray[1] = arr1.split(" ");
console.log("otherArray: " + otherArray);
for (var i = 0; i < otherArray.length; i++) {
var biggestNum = otherArray[i][0];
for (var j=0; j < otherArray[i].length; j++) {
if (otherArray[i][j] > biggestNum) {
biggestNum = (otherArray[i][j]);
console.log("big num: " + biggestNum);
}
}
largeList[i] = biggestNum;
}
console.log(largeList);
return largeList;
}