Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript Interview Question: Largest integer in array?
/*
Return the largest value in an array of non-negative integers
*/
function largestInt(arr) {
if (arr.length === 0) {
return -1;
}
return arr.reduce(comparator);
}
const comparator = ((largestValue, element) => largestValue > element ? largestValue : element);
console.log(largestInt([1,2,3,4,5,3,2,1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment