Skip to content

Commit bc20bf1

Browse files
committed
2nd code challenge
1 parent e67b6bf commit bc20bf1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

my-code-challenges/minMax.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function miniMaxSum(arr) {
2+
// Write your code here
3+
//first sort the array
4+
arr.sort((a,b) => a - b)
5+
// console.log(arr)
6+
let max = arr[0] + arr[1] + arr[2] + arr[3];
7+
let min = arr[1] + arr[2] + arr[3] + arr[4];
8+
//or one could use for loop to iterate over sorted array - add elements to find max and min
9+
console.log(`${max} ${min}`)
10+
11+
12+
}

0 commit comments

Comments
 (0)