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