Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
This'd be a good use for template literals. Here's a quicky in javascript:
functionlikesStringForNames(names){const[first,second,third]=names;switch(names.length){case0:return"no one likes this";case1:return`${first} likes this`;case2:return`${first} and ${second} like this`;case3:return`${first}, ${second} and ${third} like this`;default:return`${first}, ${second} and ${names.length-2} others like this`;}}
Sanity check:
[[],["Peter"],["Jacob","Alex"],["Max","John","Mark"],["Alex","Jacob","Mark","Max"],["Alex","Mark",...Array(10000)]].map(likesStringForNames)-->["no one likes this","Peter likes this","Jacob and Alex like this","Max, John and Mark like this","Alex, Jacob and 2 others like this","Alex, Mark and 10000 others like this"]
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.
This'd be a good use for template literals. Here's a quicky in javascript:
Sanity check: