- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayMax.js
More file actions
Latest commit
48 lines (36 loc) · 962 Bytes
/
Copy patharrayMax.js
File metadata and controls
48 lines (36 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// arrayMax.js
// array of numbers we want to find the maximum of
letourNumbers=[
4,875,23,543,12
];
//----//
// function to find the largest number in an array
functionarrayMax(whichArray)
{
// assume the first element is the largest
letmax=whichArray[0];
// loop through the array to compare each element
for(leti=1;i<whichArray.length;i++)
{
if(whichArray[i]>max)
{
// update max if current element is larger
max=whichArray[i];
}
}
// return the largest number
returnmax;
}
//----//
// call the function and pass our array
console.log(arrayMax(ourNumbers));
//----//
/*
875
*/
//----//
// Dedicated to God the Father
// All Rights Reserved Christopher Andrew Topalian Copyright 2000-2025
// https://github.com/ChristopherTopalian
// https://github.com/ChristopherAndrewTopalian
// https://sites.google.com/view/CollegeOfScripting