rsschool-cv

Profile picture

Anatoly Sizyakin

~ Frontend Developer ~

✉️ Contacts

👤 About

Interested in Web development.

🌍 Languages

💪 Tech Skills

Languages:
Key Skills:
Tools:

🎓 Education

1999-2004 | Moscow Goverment Social Univercity
2023 | Hexlet
2024 | Hexlet
2024 | Hexlet

👔 Work

2003-2008 | «Rusich» OOO
2009-2011 | OOO «Arbalet»
2011-2016 | «Polyus-M» OOO
2016-.... | Self-Employed

👨🏼‍💻 Code

Task:

Implement the function which takes an array containing the names of people that like an item. It must return the display text as shown in the examples:

[]                                -->  "no one likes this"
["Peter"]                         -->  "Peter likes this"
["Jacob", "Alex"]                 -->  "Jacob and Alex like this"
["Max", "John", "Mark"]           -->  "Max, John and Mark like this"
["Alex", "Jacob", "Mark", "Max"]  -->  "Alex, Jacob and 2 others like this"

For 4 or more names, the number in “and 2 others” simply increases.

Solution:

function likes(names) {
  switch(names.length) {
     case 0: return `no one likes this`;
     case 1: return `${names[0]} likes this`;
     case 2: return `${names[0]} and ${names[1]} like this`;
     case 3: return `${names[0]}, ${names[1]} and ${names[2]} like this`;
    default: return `${names[0]}, ${names[1]} and ${names.length - 2} others like this`;
  }
}