Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Checking for vowels in array of numbers using JavaScript
Problem
We are required to write a JavaScript function that takes in takes in an array of numbers. If in that array there exists any number which is the char code any vowel in ascii we should switch that number to the corresponding vowel and return the new array.
Example
Following is the code −
const arr = [5, 23, 67, 101, 56, 111];
const changeVowel = (arr = []) => {
for (let i=0, l=arr.length; i<l; ++i){
let char = String.fromCharCode(arr[i])
if ('aeiou'.indexOf(char) !== -1){
arr[i] = char;
};
};
return arr;
};
console.log(changeVowel(arr));
Output
[ 5, 23, 67, 'e', 56, 'o' ]
Advertisements
