Late to the party and I can see people have already posted a similar solution but just going to post anyway. Sometimes keeping it simple is OK :)
My simple solution in js
const displayLikes = (likes) => { let msg; switch(likes.length) { case 0: msg = `no one likes this` break; case 1: msg = `${likes[0]} likes this`; break; case 2: msg = `${likes[0]} and ${likes[1]} likes this`; break; case 3: msg = `${likes[0]}, ${likes[1]} and ${likes[2]} likes this`; break; default: msg = `${likes[0]}, ${likes[1]} and ${likes.length - 2} others likes this`; break; } return msg; };
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Late to the party and I can see people have already posted a similar solution but just going to post anyway. Sometimes keeping it simple is OK :)
My simple solution in js