M
M
Max Rudik2015-09-27 23:27:56
JavaScript
Max Rudik, 2015-09-27 23:27:56

How to display maximum values ​​of arrays nested in parent array?

Good afternoon!
Please help me figure it out, the task is this: the function must return an array consisting of the maximum values ​​of the arrays nested in a common array for them.

arr = ;

I wrote the function, everything works, but not quite correctly, it should turn out 27, 5, 39, 1001, but it turns out 27.27, 39, 1001. That is, the second array is knocked out of the ascending order, and its value is ignored and replaced by the value of the first . What is it, and how to deal with it?
Here is the code:
<script>
function largestOfFour(arr) {  
var high = 0;
var finArr = [];
for (var i = 0; i < arr.length; i++){//	в цикле большого массива
  var subArr = arr[i];			//определяем малые
  for (var a = 0; a < subArr.length; a++){//в каждом из малых
    if (subArr[a] > high){				//находим наибольшее значение
      high = subArr[a];
      }			
    }
        finArr.push(high);
  }	
  return finArr;
}
var q = largestOfFour(, "");
console.log(q);

</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Finom, 2015-09-27
@Finom

.map(function(v) {
  return Math.max.apply(null,v);
});

How to write a function, I think you will understand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question