-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzBuzz.js
46 lines (43 loc) · 1.12 KB
/
fizzBuzz.js
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
function fizzBuzz(n) {
valueArray = [];
for (let i = 1; i <= n; i++) {
value = '';
if ((i % 3) === 0) {
value += 'Fizz';
}
if ((i % 5) === 0) {
value += 'Buzz';
}
if (value === '') {
value = `${i}`;
}
valueArray.push(value);
console.log(value);
}
console.log(valueArray);
}
function ascendingOrder(myArray) {
const n = myArray.length;
for (let i = 0; i < n - 1; i++) {
for (let j = 0; j < n - i - 1; j++) {
if (myArray[j] > myArray[j + 1]) {
[myArray[j], myArray[j + 1]] = [myArray[j + 1], myArray[j]]
}
}
}
console.log(myArray);
}
function descendingOrder(myArray) {
const n = myArray.length;
for (let i = 0; i < n - 1; i++) {
for (let j = 0; j < n - i - 1; j++) {
if (myArray[j] < myArray[j + 1]) {
[myArray[j], myArray[j + 1]] = [myArray[j + 1], myArray[j]]
}
}
}
console.log(myArray);
}
// fizzBuzz(5);
// ascendingOrder([3, 4, 6, 3]);
// descendingOrder([3, 4, 6, 3]);