aboutsummaryrefslogtreecommitdiff
path: root/challenge-053/dave-jacoby/node/ch-1.js
blob: b0cd5fa3c629fc025e79ae5580c0e36dc5d260ad (plain)
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
#!/usr/bin/env node

vowel_strings(2);

function vowel_strings(max_len, str = '') {
  if (str.length === max_len) {
    console.log(str);
    return;
  }
  var next = [];
  var last = '';

  if (str.length > 0) {
    last = str.substring(-1, 1);
  }

  if (str === '') {
    next = ['a', 'e', 'i', 'o', 'u'];
  } else if (last === 'a') {
    next = ['e', 'i'];
  } else if (last === 'e') {
    next = ['i'];
  } else if (last === 'i') {
    next = ['a', 'e', 'o', 'u'];
  } else if (last === 'o') {
    next = ['a', 'u'];
  } else if (last === 'u') {
    next = ['e', 'o'];
  }

  const iter = next.values();
  for (const i of iter) {
    vowel_strings(max_len, str + i);
  }
}