-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathSum.js
More file actions
33 lines (28 loc) · 729 Bytes
/
Sum.js
File metadata and controls
33 lines (28 loc) · 729 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
function Somar(array) {
var total = 0;
for (var i = 0; i < array.length; i++) {
if (array[i] >= 2) {
total += array[i];
}
}
return total;
}
var array = [0, 5, 1, 2];
console.log(Somar(teste));
function Somar(array, limite) {
var total = 0;
for (var i = 0; i < array.length; i++) {
if (array[i] >= limite) {
total += array[i];
}
}
return total;
}
var array = [0, 5, 1, 2];
console.log(Somar(array, 2));
function Somar(array, limite) {
for (var i = 0, total = 0; i < array.length; (total += array[i] >= limite ? array[i] : 0), i++);
return total;
}
console.log(Somar([0, 5, 1, 2], 2));
//https://pt.stackoverflow.com/q/162708/101