this repo has no description
1var VOWELS = ['a', 'e', 'i', 'o', 'u'];
2var BAD_COMBOS = ['ab', 'cd', 'pq', 'xy'];
3
4module.exports = {
5 isStringNice1: function(str) {
6 return (
7 this.hasThreeVowels(str) &&
8 this.hasDoubleLetter(str) &&
9 !this.hasBadCombos(str)
10 );
11 },
12
13 isStringNice2: function(str) {
14 return (
15 this.hasRepeatWithBreak(str) &&
16 this.hasMatchingPairs(str)
17 );
18 },
19
20 hasThreeVowels: function(str) {
21 var count = 0;
22
23 str.split('').forEach(function(char) {
24 if (VOWELS.indexOf(char) !== -1) count++;
25 });
26
27 return count >= 3;
28 },
29
30 hasDoubleLetter: function(str) {
31 var lastChar = null;
32 var chars = str.split('');
33
34 for (var i = 0; i < chars.length; i++) {
35 if (chars[i] === lastChar) return true;
36 lastChar = chars[i];
37 }
38
39 return false;
40 },
41
42 hasBadCombos: function(str) {
43 for (var i = 0; i < BAD_COMBOS.length; i++) {
44 if (str.indexOf(BAD_COMBOS[i]) !== -1) return true;
45 }
46 return false;
47 },
48
49 hasMatchingPairs: function(str) {
50 var currentPair = null;
51
52 for (var i = 0; i < str.length; i++) {
53 var remainderOfStr = str.substring(i + 2, str.length);
54 currentPair = str[i] + str[i + 1];
55 if (remainderOfStr.indexOf(currentPair) !== -1) {
56 return true;
57 }
58 }
59
60 return false;
61 },
62
63 hasRepeatWithBreak: function(str) {
64 var currentChar = null;
65
66 for (var i = 0; i < str.length; i++) {
67 currentChar = str[i];
68 if (str[i+2] == currentChar) return true;
69 }
70
71 return false;
72 }
73};