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
Find distinct elements - JavaScript
We are required to write a JavaScript function that takes in an array of literals, such that some array elements are repeated. We are required to return an array that contains that appear only once (not repeated).
For example: If the array is:>
const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8];
Then the output should be −
const output = [5, 6];
Example
Following is the code −
const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8];
const findDistinct = arr => {
const res = [];
for(let i = 0; i Output
Following is the output in the console −
[5, 6]
Advertisements
