![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Finding mistakes in a string - JavaScript
We are required to write a JavaScript function that takes in two strings. The first string is some mistyped string and the second string is the correct version of this sting. We can assume that the two strings we are getting as argument will always have the same length.
We have to return the number of mistakes that exist in the first array.
Example
Following is the code −
const str1 = 'Tkos am er exakgrg fetwnh'; const str2 = 'This is an example string'; const countMistakes = (mistaken, correct) => { let count = 0; for(let i = 0; i < mistaken.length; i++){ if(mistaken[i] === correct[i]){ continue; }; count++; }; return count; }; console.log(countMistakes(str1, str2));
Output
Following is the output in the console −
15
Advertisements