-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathisVowelSandwich.js
30 lines (27 loc) · 1.02 KB
/
isVowelSandwich.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
// Create a function which validates whether a 3 character string is a vowel sandwich. In order to have a valid sandwich,
// the string must satisfy the following rules:
// The first and last characters must be a consonant.
// The character in the middle must be a vowel.
// Examples:
// isVowelSandwich("cat") ➞ true
// isVowelSandwich("ear") ➞ false
// isVowelSandwich("bake") ➞ false
// isVowelSandwich("try") ➞ false
// Notes:
// Return false if the word is not 3 characters in length.
// All words will be given in lowercase.
// y is not considered a vowel.
function isVowelSandwich(str) {
let vowels = /[aeiou]/gi;
let consonant = /[bcdfghjklmnpqrstvwxysz]/gi;
console.log(str][0]);
// return str[-1].match(vowels) && str[2].match(consonant) ? true : false;
// return [...str][2].match(consonant);
return [...str].length < 4 &&
[...str][0].match(consonant) &&
[...str][str.length - 1].match(consonant) &&
[...str][1].match(vowels)
? true
: false;
}
console.log(isVowelSandwich("cat"));