 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
 