-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask49.js
35 lines (28 loc) · 1.06 KB
/
task49.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Abbreviate a Two Word Name
/*Write a function to convert a name into initials. This kata strictly takes two words with one space in between them.
The output should be two capital letters with a dot separating them.
It should look like this:
Sam Harris => S.H
patrick feeney => P.F
*/
function abbrevName2(name) {
var nameArray = name.split(" ");
return (nameArray[0][0] + "." + nameArray[1][0]).toUpperCase();
}
function abbrevName(name) {
let res = name[0].toUpperCase();
for (let i = 1; i < name.length; i++) {
if (name[i] === " ") {
res += "." + name[i + 1].toUpperCase();
}
}
return res;
}
//Метод split() разбивает объект String на массив строк путём разделения строки указанной подстрокой.
/*
assert.strictEqual(abbrevName("Sam Harris"), "S.H");
assert.strictEqual(abbrevName("Patrick Feenan"), "P.F");
assert.strictEqual(abbrevName("Evan Cole"), "E.C");
assert.strictEqual(abbrevName("P Favuzzi"), "P.F");
assert.strictEqual(abbrevName("David Mendieta"), "D.M");*
*/