Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Compare two arrays of single characters and return the difference? JavaScript
We are required to compare, and get the difference, between two arrays containing single character strings appearing multiple times in each array.
Example of two such arrays are −
const arr1 = ['A', 'C', 'A', 'D']; const arr2 = ['F', 'A', 'T', 'T'];
We will check each character at the same position and return only the parts who are different.
Example
const arr1 = ['A', 'C', 'A', 'D'];
const arr2 = ['F', 'A', 'T', 'T'];
const findDifference = (arr1, arr2) => {
const min = Math.min(arr1.length, arr2.length);
let i = 0;
const res = [];
while (i Output
And the output in the console will be −
[
'A', 'F', 'C',
'A', 'A', 'T',
'D', 'T'
]
Advertisements
