1const fullName = nameString.split(' ');
2const initials = fullName.shift().charAt(0) + fullName.pop().charAt(0);
3return initials.toUpperCase();
1const fullName1 = "Noah William";
2const fullName2 = "Jackson";
3
4const getInitials = (name) => {
5 let initials = name.split(' ');
6
7 if(initials.length > 1) {
8 initials = initials.shift().charAt(0) + initials.pop().charAt(0);
9 } else {
10 initials = name.substring(0, 2);
11 }
12
13 return initials.toUpperCase();
14}
15
16console.log(getInitials(fullName1)) // NW
17console.log(getInitials(fullName2)) // JA