JSFiddle - React, Tailwind, and code Playground
by _sir
HTML
<h3>Take an array and return the number of unique duplicates in it</h3>
<p>
<strong>Your answer should be: </strong>0, 1, 2
</p>
<div id="output"></div>
JavaScript
var arr = [[1, 2, 3],[1, 1, 2, 3],[1, 2, 2, 3, 3, 3]];
const countInArray = (value, array) => {
return array.filter(arrValue=>(arrValue === value)).length;
}
let output = [];
arr.map((array)=>{
let count = 0;
array.map(value=>{
const countsInArray = countInArray(value, array);
if(countsInArray > 1){
count = count+1;
}
array = array.filter(arrValue=>arrValue !== value);
})
console.log("value", count);
output.push(count);
});
let outputText = '';
output.map(value=>{
outputText = outputText + ', ' + value
});
document.getElementById("output").innerHTML = outputText.substr(1, outputText.length);