JavaScript Coding Interview Question - Part 2 - Find Duplicate Element from an Array

preview_player
Показать описание
Hello everyone I have started a series on JavaScript Coding Interview Question in which I will provide some coding related interview question and also i will give the solution in my video. So, in this video I will show you how you can find Duplicate Element from an Array which is common question which asked in every javascript inteview round.

So, guys stay tuned on this channel and in upcoming day i will be uploading more video related to JavaScript Coding Interview Question
Рекомендации по теме
Комментарии
Автор

this will not work if any element present more than 2 times because you are check only i+1 element

bibhasash
Автор

But it wont work if we are about to compare let say element at i and element at i+3.

khairiyusoff
Автор

This is not correct logic, its not applying on this arr = [2, 9, 3, 4, 6, 4, 5, 6, 6, 7, 88, 88, 9]

nagireddypanditi
Автор

var arr = [1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9];
var findDuplicates = (arr)=>{
let sortedArray = arr.slice().sort();
let results = [];
for(var i=0;i<=sortedArray.length - 1;i++){
if(sortedArray[i+1] === sortedArray[i]){

}
}
return results;
}
var duplicatesArray = findDuplicates(arr);
var duplicateArray = Array.from(new Set(duplicatesArray));
console.log(duplicateArray);
var count = 0;
for(var i=0;i <= duplicateArray.length - 1;i++){
count++;
}
console.log(count);





Try this one u will get exact results with count please let me know it is working or not in reply

IRONMan-
Автор

we can try this mathod let Names = ['hridoy', 'ripa', 'mohasin', 'baba', 'hridoy', 'ripa', 'adnan', 'baba', 'adnan', 'anas', 'adnan'];
let filterNames = [];

for(let i = 0; i < Names.length; i++){
let totalName = Names[i];
=== false){
filterNames.push(totalName)
}
}

console.log(filterNames)

freecourse