-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathwarmUp6.js
More file actions
55 lines (49 loc) · 1.21 KB
/
Copy pathwarmUp6.js
File metadata and controls
55 lines (49 loc) · 1.21 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
53
54
55
// 1-implement the function mult that takes a single parameter n, and computes the multiplication of all integers up to n
//starting from 0, e.g.:
mult(3); // => 6
mult(4); // => 24
function mult(n) {
// your code is here
}
function mult(number) {
var result = 1;
var string = [];
var strIterator = 1 ;
for (var i = 1; i <= number; i++) {
result *=i;
}
//stating from here is the solution for question 2
while(strIterator < number) {
if(strIterator === 1){
string.push(1)
strIterator++;
} else {
string.push(strIterator+ " "+ strIterator );
strIterator++;
}
return result;
return string.join(' ');
}
// 2- Use a while loop to build a single string with the numbers 1 through n
// separated by the number next to the current number.
//Have it return the new string.
// eg= 1 2 2 3 3 4 4 5 5 6 6 ...
//The Impelentation in the first function
function mult(number) {
var result = 1;
var string = [];
var strIterator = 1 ;
for (var i = 1; i <= number; i++) {
result *=i;
}
while(strIterator < number) {
if(strIterator === 1){
string.push(1)
strIterator++;
} else {
string.push(strIterator+ " "+ strIterator );
strIterator++;
}
return result;
return string.join(' ');
}