[JS Practice] like function(类似Facebook上的一个点赞方法)

Title :
Like function(类似Facebook上的一个点赞方法)

You probably know the “like” system from Facebook and other pages. People can “like” blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.

Implement a function likes(), which must take in input array, containing the names of people who like an item. It must return the display text as shown in the examples:

likes([]); // must return “no one likes this”
likes([‘Peter’]); // must return “Peter likes this”
likes([‘Jacob’, ‘Alex’]); // must return “Jacob and Alex like this”
likes([‘Max’, ‘John’, ‘Mark’]); // must return “Max, John and Mark like this”
likes([‘Alex’, ‘Jacob’, ‘Mark’, ‘Max’]); // must return “Alex, Jacob and 2 others like this”
For more than 4 names, the number in and 2 others simply increases.

Continue reading

[JS practice] Square Sum (平方求和)

Title :
Square Sum (对数组中每个元素求平方,然后求和)

Description :
Complete the squareSum method so that it squares each number passed into it and then sums the results together.


For example:
squareSum([1,2, 2]); // should return 9

Continue reading