Skip to content

Commit 7a61235

Browse files
02-basic-challenges-2/03-display-likes/display-likes.test.js
1 parent 95f3d16 commit 7a61235

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
function displayLikes() {}
1+
function displayLikes(names) {
2+
let length = names.length;
3+
4+
if (length === 0) {
5+
return "no one likes this";
6+
} else if (length === 1) {
7+
return `${names} likes this`;
8+
} else if (length === 2) {
9+
return `${names[0]} and ${names[1]} like this`;
10+
} else if (length === 3) {
11+
return `${names[0]}, ${names[1]} and ${names[2]} like this`;
12+
} else {
13+
return `${names[0]}, ${names[1]} and ${length - 2} others like this`;
14+
}
15+
16+
// "Peter likes this";
17+
// "Jacob and Alex like this";
18+
// "Max, John and Mark like this";
19+
// "Alex, Jacob and 2 others like this";
20+
// "Alex, Jacob and 3 others like this";
21+
}
222

323
module.exports = displayLikes;

0 commit comments

Comments
 (0)