Created
January 24, 2021 17:13
-
-
Save KakoozaJerry/e60dec2f5399727fe33c0f0bf5b0a055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = [1,3,3,4,4,4] | |
function countDuplicate(numbers){ | |
//write your code here | |
//var result = {} | |
var result = {} | |
numbers.forEach(function(x){ | |
result[x] = (result[x] || 0) + 1; | |
}); | |
numbers.filter((item,x)=>numbers.indexOf(item)==x) | |
//console.log(result) | |
for(let k in result){ | |
//Do stuff where key would be 0 and value would be the object | |
if (result[k] == 1 ){ | |
delete result[k] | |
} | |
} | |
console.log(Object.keys(result).length) | |
for(let x in result){ | |
var arr = []; | |
arr.push(x) | |
console.log(x) | |
} | |
//var energy = arr.join(" "); | |
console.log(arr) | |
console.log("There are " + Object.keys(result).length + " non unique elements in the array" + arr.toString()) | |
} | |
countDuplicate(numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment