Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript coding challenges with solutions

Q) Find all the duplicated values in given array.
	//input : [1,2,4,3,2,1,3]
	//output: [1,2,3]
Solution)

	var findDuplicates = (arr) => {
      let newArr = arr.filter((e,i ,a) => a.indexOf(e) != a.lastIndexOf(e) )
        return [...new Set(newArr)];
    };

    let nums = [1,2,4,3,2,1,3];
    let reqArr = findDuplicates(nums);
    console.log(reqArr);
 
PREVIOUS NEXT
Tagged: #javascript #coding #challenges #solutions
ADD COMMENT
Topic
Name
2+4 =