- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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!!!!
- Related Articles
- Encrypting a string using Caesar Cipher in JavaScript
- Encrypting a string JavaScript
- Encrypting a string based on an algorithm using JavaScript
- Encrypting a string based on an algorithm in JavaScript
- Returning lengthy words from a string using JavaScript
- Encrypting Passwords in PHP
- Validating string with reference to array of words using JavaScript
- Encrypting and Decrypting Directory in Linux
- Constructing a sentence based on array of words and punctuations using JavaScript
- Replace words of a string - JavaScript
- Reversing the prime length words - JavaScript
- Reversing words within a string JavaScript
- What are Reserved Words in JavaScript?
- Expressive words problem case in JavaScript
- Order an array of words based on another array of words JavaScript

Advertisements