- 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
Find the dissimilarities in two strings - JavaScript
We are required to write a JavaScript function that takes in two strings and find the number of corresponding dissimilarities in the strings
The corresponding elements will be dissimilar if they are not equal. Let’s say the following are our two string −
const str1 = 'Hello world!!!'; const str2 = 'Hellp world111';
Example
Following is the code −
const str1 = 'Hello world!!!'; const str2 = 'Hellp world111'; const dissimilarity = (str1 = '', str2 = '') => { let count = 0; for(let i = 0; i < str1.length; i++){ if(str1[i] === str2[i]){ continue; }; count++; }; return count; }; console.log(dissimilarity(str1, str2));
Output
Following is the output in the console −
4
Advertisements