Counting Elements
Description
null
Solution(javascript)
/**
* @param {number[]} arr
* @return {number}
*/
var countElements = function(arr) {
const set = new Set()
arr.forEach(num => set.add(num))
return arr.reduce((acc, num) => {
if(set.has(num+1)){
return acc + 1
}
return acc
},0)
};