https://www.codewars.com/kata/59df2f8f08c6cec835000012
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
John has invited some friends. His list is:
s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill";
Could you make a program that
- makes this string uppercase
- gives it sorted in alphabetical order by last name.
When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma.
So the result of function meeting(s) will be:
"(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)"
It can happen that in two distinct families with the same family name two people have the same first name too.
Notes
- You can see another examples in the "Sample tests".
코드
function meeting(s) {
return s.toUpperCase().split(';').map(el => el.split(':').reverse()).sort().map(el => `(${el.join(', ')})`).join('');
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Area of a Square (8 kyu) / JavaScript (0) | 2023.04.12 |
---|---|
[Codewars] Correct the mistakes of the character recognition software (8 kyu) / JavaScript (0) | 2023.04.11 |
[Codewars] Return the day (8 kyu) / JavaScript (0) | 2023.04.10 |
[Codewars] Is it a palindrome? (8 kyu) / JavaScript (0) | 2023.04.09 |
[Codewars] Training JS #5: Basic data types--Object (8 kyu) / JavaScript (0) | 2023.04.08 |
댓글