I can’t understand the line “results[i] = largestNumber”, anybody can help me with this? Thanks!
and the question goes like this:
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
Remember, you can iterate through an array with a simple for loop, and access each member with array syntax arr[i] .
Did you try to debug this? I often just copy a set code example and try to pass through the code line by line (I use VS code and debug within it). This code just passes through the array, and at the very end (the line you are asking about) of the loop assigns the largest number to the array. In the first position results[i] is result[0] which gets the 5. Then result[1] is 27 and so forth.
Is setting the variable largestNumber to be equal to the 1st value in each sub-array. The nested for loop is comparing the rest of the elements in the sub-array to the 1st one which is the largest number. So if any are larger, then that variable gets updated. If the 1st element is the largest, then it does not.
results[i] = largest number; is adding the largest number to the empty array at each index - it is assigning values to the empty array.