DEV Community

loading...

Discussion on: Daily Challenge #48 - Facebook Likes

Collapse
themisir profile image
Misir Jafarov
function x(likes) {
  return (function (){
    if (likes.length == 0) return 'no one';
    if (likes.length == 1) return likes[0];
    if (likes.length < 4) {
        var b = likes.pop();
            return likes.join(', ') + ' and ' + b;
    }
    return `${likes[0]}, ${likes[1]} and ${likes.length - 2} others`;   
  })() + ' likes this';
}