Basic Algorithm Scripting - Return Largest Numbers in Arrays

Tell us what’s happening:
Describe your issue in detail here.
I spend the whole day trying to figure this out, firstly I understood it wrong, I thought It asks for the biggest number in a total of each array and prints out the biggest, which you can tell by code.
But it is asking for which subset is the largest, I was thinking of doing total and updating the key of the obj and then checking with Object.keys and using Math.max.

I am lost on how to update the object key with total value of items in array or am I thinking wrong?
Your code so far

function largestOfFour(arr) {
  //loop over each set of array
  let count = 0;
  let total = 0;
  let totalArray = []
  let obj = {
  //create object
  for(let i = 0; i < arr.length;i++){
    obj[i] = arr[i]
  //loop over object
  for(let number in obj){
     //assign each array dataset to arr
      const arr = obj[number];
    for(let i = 0; i < arr.length; i++){
      total += arr[i]
    count +=1

  //add each number in array and push add it object
  //grab the higest number is total
  return arr;

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Return Largest Numbers in Arrays

Link to the challenge:

Nope that is not what it wants.

It wants the largest number in each given array.

They will give you one array contains exactly 4 arrays of numbers

You must identify the largest number in each array and return another array containing those largest values.

1 Like