나는 이렇게 학습한다/Algorithm & SQL

0106. Is there a vowel in there?

daco2020 2023. 1. 7. 23:16
반응형

Given an array of numbers, check if any of the numbers are the character codes for lower case vowels (a, e, i, o, u).

If they are, change the array value to a string of that vowel.

Return the resulting array.



Solution:

function isVow(a){
  for (let index in a) {
    let vow = String.fromCharCode(a[index])
    if (["a", "e", "i", "o", "u"].includes(vow)) {
      a[index] = vow
    }
  }
  return a
}
const isVow = a => a.map(x=>'aeiou'.includes(y=String.fromCharCode(x)) ? y : x)


반응형