// getting max number in array without using array.reduce() method
function maxOfArray(array)
{
// set maxElement to 0 index of array i.e. 1
let maxElement = array[0];
// loop till array.length exusted and increament i by 1 with each iteration
for(let i=1; i<=array.length; i++)
{
// if current index of array value in loop is greater than maxElement
// save value of array[i] in variable maxElement
// else go for next iteration
// do same process until loop end and return final value of maxElement on console.
if(array[i] > maxElement)
{
maxElement = array[i];
}
}
return maxElement;
}
const maxResult = [1,5,3,6,10,2,2,5];
console.log(maxOfArray(maxResult));
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.