Skip to content

Commit 5d54036

Browse files
author
umbur
committed
completes aplify
1 parent 1b44133 commit 5d54036

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

amplify.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// In this challenge, you must generate a sequence of consecutive numbers, from a lower bound that will always be equal to 1, up to
2+
// a variable given higher bound (including the bounds in the sequence).
3+
// Each number of the sequence that can be exactly divided by 4 must be amplified by 10 (see notes below).
4+
// Given a higher bound num, implement a function that returns an array with the sequence of numbers, after that every multiple of
5+
// 4 has been amplified.
6+
7+
// Examples:
8+
// amplify(4) ➞ [1, 2, 3, 40]
9+
// Create a sequence from 1 to 4
10+
// 4 is exactly divisible by 4, so it will be 4*10 = 40
11+
// amplify(3) ➞ [1, 2, 3]
12+
// Create a sequence from 1 to 3
13+
// There are no numbers that can be exactly divided by 4
14+
// amplify(25) ➞ [1, 2, 3, 40, 5, 6, 7, 80, 9, 10, 11, 120, 13, 14, 15, 160, 17, 18, 19, 200, 21, 22, 23, 240, 25]
15+
// Create a sequence from 1 to 25
16+
// The numbers exactly divisible by 4 are: 4 (4*10 = 40), 8 (8 * 10 = 80)... and so on.
17+
18+
// Notes:
19+
// The given parameter num will always be equal to or greater than 1.
20+
// Remember to include the num as the higher bound of the sequence (see the Examples) above.
21+
// A number a amplified by a factor b can also be read as: a * b.
22+
// A number a is exactly divisible by a number b when the remainder of the division a / b is equal to 0.
23+
// If you get stuck on a challenge, find help in the Resources tab.
24+
// If you're really stuck, unlock solutions in the Solutions tab.
25+
26+
function amplify(num) {
27+
let result = [];
28+
for (let i = 1; i <= num; i++) {
29+
if (i % 4 == 0) {
30+
result.push(i * 10);
31+
} else {
32+
result.push(i);
33+
}
34+
}
35+
return result;
36+
}
37+
console.log(amplify(25));

chatroomStatus.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Write a function that returns the number of users in a chatroom based on the following rules:
2+
// If there is no one, return "no one online".
3+
// If there is 1 person, return "user1 online".
4+
// If there are 2 people, return "user1 and user2 online".
5+
// If there are n>2 people, return the first two names and add "and n-2 more online".
6+
// For example, if there are 5 users, return:
7+
// "user1, user2 and 3 more online"
8+
9+
// Examples:
10+
// chatroomStatus([]) ➞ "no one online"
11+
// chatroomStatus(["paRIE_to"]) ➞ "paRIE_to online"
12+
// chatroomStatus(["s234f", "mailbox2"]) ➞ "s234f and mailbox2 online"
13+
// chatroomStatus(["pap_ier44", "townieBOY", "panda321", "motor_bike5", "sandwichmaker833", "violinist91"])
14+
// ➞ "pap_ier44, townieBOY and 4 more online"
15+
16+
function chatroomStatus(users) {
17+
// console.log(users.length);
18+
if (users.length === 0) {
19+
return "no one online";
20+
} else if (users.length === 1) {
21+
return `${users[0]} online`;
22+
} else if (users.length === 2) {
23+
return `${users[0]} and ${users[1]} online`;
24+
} else {
25+
return `${users[0]}, ${users[1]} and ${users.length - 2} more online`;
26+
}
27+
}
28+
console.log(
29+
chatroomStatus([
30+
"pap_ier44",
31+
"townieBOY",
32+
"panda321",
33+
"motor_bike5",
34+
"sandwichmaker833",
35+
"violinist91",
36+
])
37+
);

0 commit comments

Comments
 (0)