function largestOfFour(arr) {
// You can do this
var total = [];
for (var i = 0; i< arr.length; i++) {
console.log(Math.max.apply(null, arr[i]));
}
return total;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
The console is returning the largest numbers from each array within the array but I dont think in array format, Where am i going wrong here?
Looks like you are correctly finding the biggest number in each array but make sure you are pushing that into total array because you are returning the total array in the end.
How would i push it into the array? I am currently having the same issue with the TITLE CASE A SENTENCE algorithm. It shows the correct output using console.log. However when I use the push method, it no longer shows up?
Here is my code for that
function titleCase(str) {
var arr = str.split(' ')
for (var i = 0; i < str.length; i++ ) {
var cap = console.log(arr[i].charAt(0).toUpperCase() + arr[i].slice(1))
arr = arr.push(cap)
}
return arr
}
titleCase("I'm a little tea pot");
````````````````````
function largestOfFour(arr) {
// You can do this
var total = [];
for (var i = 0; i< arr.length; i++) {
console.log(Math.max.apply(null, arr[i]));
}
return total;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
you never add the number you find inside the for loop to the total. Keep in mind that you override arr with arr.push when you do this: arr = arr.push(cap) . arr.push(cap) is enough to push cap onto arr.