Answers for "another finding dublicates in array"

0

another finding dublicates in array

const yourArray = [1, 1, 2, 3, 4, 5, 5]

const yourArrayWithoutDuplicates = [...new Set(yourArray)]

let duplicates = [...yourArray]
yourArrayWithoutDuplicates.forEach((item) => {
  const i = duplicates.indexOf(item)
  duplicates = duplicates
    .slice(0, i)
    .concat(duplicates.slice(i + 1, duplicates.length))
})

console.log(duplicates) //[ 1, 5 ]
Posted by: Guest on May-17-2021

Code answers related to "another finding dublicates in array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language