-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.Wars.js
17 lines (11 loc) · 852 Bytes
/
C.Wars.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* A person's full name is usually composed of a first name, middle name and last name; however in some cultures (for example in South India) there may be more than one middle name.
Write a function that takes the full name of a person, and returns the initials, separated by dots ('.'). The initials must be uppercase. The last name of the person must appear in full, with its first letter in uppercase as well.
See the pattern below:
"code wars" ---> "C.Wars"
"Barack hussein obama" ---> "B.H.Obama"
Names in the full name are separated by exactly one space (' ' ) ; without leading or trailing spaces. Names will always be lowercase, except optionally their first letter.
*/
//solution
function initials(n) {
return n.split(' ').map((v, i, a) => v.charAt(0).toUpperCase() + (i == a.length - 1 ? v.slice(1) : '.')).join('');
}