![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 and returning uncommon characters between two strings in JavaScript
Problem
We are required to write a JavaScript function that takes in two strings. Our function should return a new string of characters which is not common to both the strings.
Example
Following is the code −
const str1 = "xyab"; const str2 = "xzca"; const findUncommon = (str1 = '', str2 = '') => { const res = []; for (let i = 0; i < str1.length; i++){ if (!(str2.includes(str1[i]))){ res.push(str1[i]) } } for (let i = 0; i < str2.length; i++){ if (!(str1.includes(str2[i]))){ res.push(str2[i]) } } return res.join(""); }; console.log(findUncommon(str1, str2));
Output
ybzc
Advertisements