largest numbers in an array fcc code example

Example 1: freecodecamp basic algorithm scripting return largest numbers in arrays

function largestOfFour(arr) {
  var newArr = [];
for(var i = arr.length - 1; i >= 0; i--){
  arr[i].sort(function(a, b){return a - b});
newArr.push(arr[i][arr.length - 1])
}
 newArr.sort(function(a, b){return -b - a});
  return newArr;
}

Example 2: rite a function that takes in an array of numbers and outputs the maximum number.

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