-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathej4_1.js
More file actions
52 lines (45 loc) · 1.25 KB
/
Copy pathej4_1.js
File metadata and controls
52 lines (45 loc) · 1.25 KB
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
48
49
50
51
52
/* Hacer dos funciones:
* - sum(...array) -> suma todos los numeros que contenga el array
* - range(start, end, step) -> Crea un array que contiene todos los numeros desde start a end con un salto step. Si step no se especifica sera 1.
*/
let sum = function(array){
let res = 0;
for(let i = 0 ; i < array.length ; i++){
res += parseInt(array[i]);
}
return res;
}
function range(...arguments){
let start = 0;
let end = 0;
let step = 1;
if(arguments.length == 1){
end = parseInt(arguments[0]);
}
else if(arguments.length == 2){
start = parseInt(arguments[0]);
end = parseInt(arguments[1]);
}
else if(arguments.length >= 3){
start = parseInt(arguments[0]);
end = parseInt(arguments[1]);
step = parseInt(arguments[2]);
}
let res = [];
for(let i = start ; i <= end ; i += step){
res.push(i);
}
return res;
}
function introducir(n){
let res = [];
for(let i = 0 ; i < n ; i++){
res.push(prompt('Introduzca un numero'));
}
return res;
}
let x = prompt('start');
//let y = prompt('end');
//let z = prompt('step');
console.log(range(x));
console.log(sum(range(x)));