Last active
November 12, 2022 18:11
-
-
Save MrVanQish/6944e3f46798f971b6d75b099a38779e to your computer and use it in GitHub Desktop.
Array de personas que han reaccionado a un post para retornar un string con info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const likesPerPeople = (peopleArray: Array<string>): string => { | |
switch (peopleArray.length) { | |
case 0: | |
return 'No one like this'; | |
case 1: | |
return peopleArray[0] + ' likes this'; | |
case 2: | |
return peopleArray[0] + ' and ' + peopleArray[1] + ' like this'; | |
case 3: | |
return peopleArray[0] + ', ' + peopleArray[1] + ' and ' + peopleArray[2] + ' like this'; | |
default: | |
return peopleArray[0] + ', ' + peopleArray[1] + ' and ' + (peopleArray.length - 2) + ' others like this' | |
} | |
} | |
console.log(likesPerPeople(['Alex','Jacob','Mark', 'Max', 'Ada', 'Elias'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First one!