Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions codewars/6kyu/vowel-recognition/koronya.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// [JS][6kyu] Vowel Recognition
// vowel-recognition
// https://www.codewars.com/kata/5bed96b9a68c19d394000b1d/train/javascript

const vowelSet = new Set(['a', 'e', 'i', 'o', 'u'])
const isVowel = (char) => vowelSet.has(char)

const vowelRecognition = (input) => {
const str = input.toLowerCase()
const strLength = str.length
let total = 0
for (let i = 0; i < strLength; i += 1 || 0) {
if (isVowel(str[i])) {
total += (i + 1) * (strLength - i)
}
}
return total
}

vowelRecognition('bbbb') === 0
vowelRecognition('baceb') === 16
vowelRecognition('aeiou') === 35
vowelRecognition('aeiouAEIOU') === 220