-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
aliasGen.js
19 lines (11 loc) · 1.02 KB
/
aliasGen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*Your task is to create a function that, given a proper first and last name, will return the correct alias.
Two objects that return a one word name in response to the first letter of the first name and one for the first letter of the surname are already given.
If the first character of either of the names given to the function is not a letter from A - Z, you should return "Your name must start with a letter from A - Z."
Sometimes people might forget to capitalize the first letter of their name so your function should accommodate for these grammatical errors.
var firstName = {A: 'Alpha', B: 'Beta', C: 'Cache' ...}
var surname = {A: 'Analogue', B: 'Bomb', C: 'Catalyst' ...}
aliasGen('Larry', 'Brentwood') === 'Logic Bomb'
aliasGen('123abc', 'Petrovic') === 'Your name must start with a letter from A - Z.'
*/
//Answer//
let aliasGen=(a,b)=>(/[A-Z]/).test(a.toUpperCase()[0])&&(/[A-Z]/).test(b.toUpperCase()[0])?`${firstName[a.toUpperCase()[0]]} ${surname[b.toUpperCase()[0]]}`:"Your name must start with a letter from A - Z."