Skip to content

Instantly share code, notes, and snippets.

@shahidcodes
Last active April 12, 2017 10:36
Show Gist options
  • Save shahidcodes/d4afe798af3872a1c0f47f8fbe8efcce to your computer and use it in GitHub Desktop.
Save shahidcodes/d4afe798af3872a1c0f47f8fbe8efcce to your computer and use it in GitHub Desktop.
FrontEndAlgorithm | Largest number freeCodeCamp https://www.freecodecamp.com/challenges/return-largest-numbers-in-arrays
function largestOfFour(arr) {
// You can do this!
// Override Array Object
Array.prototype.max = function(){
piv = 0
this.forEach((n)=>{
if(piv<n ) {
piv = n
}
})
return piv
}
var finalResult = []
arr.forEach((x)=>{
finalResult.push(x.max())
})
console.log(finalResult)
return finalResult;
}
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