 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Matching strings for similar characters - JavaScript
We are required to write a JavaScript function that accepts two string and a number n.
The function matches the two strings i.e., it checks if the two strings contains the same characters.
The function returns true if both the strings contain the same character irrespective of their order or if they contain at most n different characters, else the function should return false.
Example
Following is the code −
const str = 'some random text'; const str2 = 'some r@ndom text'; const deviationMatching = (first, second, num) => {    let count = 0;    for(let i = 0; i < first.length; i++){       if(!second.includes(first[i])){          count++;       };       if(count > num){          return false;       };    };    return true; }; console.log(deviationMatching(str, str2, 1));  Output
This will produce the following output in console −
true
Advertisements
 