

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
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
- Related Questions & Answers
- Differences in two strings in JavaScript
- Difference between two strings JavaScript
- Find uncommon characters of the two strings in C++
- Twice join of two strings in JavaScript
- Hamming Distance between two strings in JavaScript
- Finding gcd of two strings in JavaScript
- Find uncommon characters of the two strings in C++ Program
- Finding shared element between two strings - JavaScript
- Construct objects from joining two strings JavaScript
- How to merge two strings alternatively in JavaScript
- Joining two strings with two words at a time - JavaScript
- What is the best way to compare two strings in JavaScript?
- How to compare two strings in the current locale with JavaScript?
- Finding the longest common consecutive substring between two strings in JavaScript
- Program to find the minimum edit distance between two strings in C++
Advertisements