Return Largest Numbers in Arrays Where am i going wrong?

Tell us what’s happening:

Your code so far


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?

One thing I see 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");

````````````````````

If you are having trouble with a different challenge, I suggest opening a different topic using the “Ask For Help” button in the challenge.

In this case, your problem is with this line:
arr = arr.push(cap)

The .push method changes the array in-place and doesn’t return anything useful.

Apologies!
Still doesn’t work for me even if i create an empty array and push to that? Thanks for the help.

push() returns a number, so with the line arr = arr.push(cap) you are making arr a number

If you change something please show again whole code

But please, open a new thread for help with the other challenge and here show where you are with the find largest number challenge

Hey @shab, newbie here,

But for the first problem with multi-dimensional arrays - the push() method would be in the line as in the following:

total.push[[0],[1]],[[1],[1]],[[2],[3]],[[3],[[3],[1]];

Again I’m newbie here. If all else fails, google!

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.

You need to use round parenthesis for methods, it will never work if you use square brackets

Ah, @ilenia thus my own comment as a newbie. I appreciate the correction.

Peace!