Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Created September 25, 2021 10:28
Show Gist options
  • Save Stefanacef/55ecfbc92446cdefcbe599a2785258a5 to your computer and use it in GitHub Desktop.
Save Stefanacef/55ecfbc92446cdefcbe599a2785258a5 to your computer and use it in GitHub Desktop.
largest number from each provided sub-array| Solution | JavaScript
//Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
function largestOfFour(arr) {
subArr=[];
arr.map((val)=>{
return subArr.push(Math.max(...val))
})
return subArr;
}
console.log(largestOfFour([
[4, 5, 1, 3],
[13, 27, 18, 26],
[32, 35, 37, 39],
[1000, 1001, 857, 1],
]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment