-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumLargestNum.js
More file actions
47 lines (42 loc) · 830 Bytes
/
SumLargestNum.js
File metadata and controls
47 lines (42 loc) · 830 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
let first;
let second;
let index;
const sumLargestNumbers = function(data) {
//for first number
for (let i = 0; i < data.length; i++) {
if (i == 0) {
if (data[i] > data[i+1]) {
first = data[i];
index= i;
}
else {
first= data[i] + 1;
index= i + 1;
}
} else {
if (first < data[i + 1]) {
first = data[i + 1];
index = i + 1;
}
}
}
//for second number
data.splice(index,1);
for (let j= 0; j < data.length; j++) {
if (j== 0) {
if (data[j] > data[j+1]) {
second= data[j];
}
else {
second = data[j] + 1;
}
} else {
if (second < data[j + 1]) {
second= data[j + 1];
}
}
}
let sum = second + first;
return sum;
}
console.log(sumLargestNumbers([10, 4, 34, 6, 92, 2]));