7. How to find duplicate elements from an Array

  

        //var myArr = [ 'x','y','a','x','b','b','a','c','b','k','b' ];
        var myArr = [ 6, 4, 5, 5, 5, 2, 1, 3, 1, 1, 2, 1, 3, 4, 7 ];

        // you must need to sort the array first
        var myArrSorted = myArr.sort();

        // in filter function
        // 1st parameter is each element from an array
        // 2nd parameter is index of each element
        // 3rd parameters is an array itself
        // so we need to check if each element with its next element and
        // return only if element is not duplicate
        var result = myArrSorted.filter( function(element,index,arrayitself){
        if(element !== arrayitself[index+1]){
        return element;
        }
        });

        console.log(result);