- Trending Categories
- 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
Turn each character into its ASCII character code and join them together to create a number in JavaScript
Problem
We are required to write a JavaScript function that takes in a string. Our function should turn each character into its ASCII character code and join them together to create a number. Then we should replace all instances of 7 from this number to 1 to construct another number. Finally, we should return the difference of both these numbers
Example
Following is the code −
const str = 'AVEHDKDDS'; const ASCIIDifference = (str = '') => { return str .split('') .map(c => c.charCodeAt(0)) .join('') .split('') .map(Number) .filter(str => str === 7) .length * 6; }; console.log(ASCIIDifference(str));
Output
12
Advertisements