Answers for "find unique element in an array where all other elements are repeating twice"

0

function to find the unique elements from two arrays

var array3 = array1.filter(function(obj) { return array2.indexOf(obj) == -1; });
Posted by: Guest on June-21-2021
0

Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array

const arrayNonUniq = array => {
    if (!Array.isArray(array)) {
        throw new TypeError("An array must be provided!")
    }

    return array.filter((value, index) => array.indexOf(value) === index && array.lastIndexOf(value) !== index)
}

arrayNonUniq([1, 1, 2, 3, 3])
//=> [1, 3]

arrayNonUniq(["foo", "foo", "bar", "foo"])
//=> ['foo']
Posted by: Guest on August-11-2021

Code answers related to "find unique element in an array where all other elements are repeating twice"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language