Last active
August 10, 2018 12:09
-
-
Save woochica/4f0b91f348ff95f06f0252feee1fa792 to your computer and use it in GitHub Desktop.
CodeWards "Consonant please" kata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatten(arr) { | |
const len = arr.length; | |
for (let i = 0; i < len; i++) { | |
arr.push(...arr.shift()); | |
} | |
return arr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortLetters(arr) { | |
let flattenedArr = flatten(arr), | |
letters = removeNumbers(flattenedArr), | |
upperCaseLetters = arrayToUpperCase(letters); | |
return upperCaseLetters; | |
} | |
function arrayToUpperCase(arr) { | |
return arr.map(function(value) { | |
return value.toUpperCase(); | |
}); | |
} | |
function removeNumbers(arr) { | |
let letters = [] | |
for (let element of arr) { | |
if (typeof element == 'string') { | |
letters.push(element); | |
} | |
} | |
return letters; | |
} | |
function flatten(arr) { | |
let flattenedArr = []; | |
for (let element of arr) { | |
flattenedArr.push(...element); | |
} | |
return flattenedArr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sortLetters = (arr) => { | |
const len = arr.length; | |
const vowelIdx = len; | |
const consonantIdx = len + 1; | |
arr[vowelIdx] = []; | |
arr[consonantIdx] = []; | |
for (let i = 0; i < len; i++) { | |
for (let j = 0; j < arr[i].length; j++) { | |
let char = arr[i][j]; | |
if (typeof char == "string") { | |
if (isVowel(char)) { | |
arr[vowelIdx].push(char.toUpperCase()); | |
} else { | |
arr[consonantIdx].push(char.toUpperCase()); | |
} | |
} | |
} | |
} | |
arr.splice(0, len); | |
return arr; | |
}; | |
const isVowel = (char) => { | |
const vowels = "aeiou"; | |
return vowels.indexOf(char) >= 0 ? true : false; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sortLetters([[1,"a","H"],[3,"o","s"],[4,"E","i"]]); | |
sortLetters([["c","A",2],[5,"e","x"],[9,"W","U"]]); | |
sortLetters([["a",2,"Q"],["I",3,"n"],["E",6,"i"]]); | |
sortLetters([[9,"i","H"],[0,"U","s"],[1,"o","J"]]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment