हमें एक JavaScript फ़ंक्शन लिखना है जो दो स्ट्रिंग्स लेता है और उनमें संबंधित भिन्नताओं (dissimilarities) की संख्या ढूँढता है।
संबंधित तत्व भिन्न होंगे यदि वे बराबर नहीं हैं। मान लीजिए हमारी दो स्ट्रिंग्स हैं:
const str1 = 'Hello world!!!'; const str2 = 'Hellp world111';
कोड
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));
आउटपुट
4