Skip to content

Instantly share code, notes, and snippets.

@MrVanQish
Last active November 12, 2022 18:11
Show Gist options
  • Save MrVanQish/6944e3f46798f971b6d75b099a38779e to your computer and use it in GitHub Desktop.
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
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']))
@MrVanQish
Copy link
Author

First one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment