- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Encrypting censored words using JavaScript
Problem
We are required to write a JavaScript function that takes in a string. Our function should convert the string according to following rules −
The words should be Caps, Every word should end with '!!!!', Any letter 'a' or 'A' should become '@', Any other vowel should become '*'.
Example
Following is the code −
const str = 'ban censored words'; const maskWords = (str = '') => { let arr=str.split(' '); const res=[] for (let i=0; i<arr.length; ++i){ let s=(arr[i].toUpperCase()+'!!!!').split(''); for (let j=0; j<s.length; ++j){ if (s[j]=='A') s[j]='@'; if (s[j]=='E'||s[j]=='I'||s[j]=='O'||s[j]=='U') s[j]='*'; } res.push(s.join('')); }; return res.join(' ') }; console.log(maskWords(str));
Output
B@N!!!! C*NS*R*D!!!! W*RDS!!!!
Advertisements
To Continue Learning Please Login
Login with Google