function Count(arr = []){ return arr.reduce((t, v) => (t[v] = (t[v] || 0) + 1, t), {}) } const arr = [0, 1, 1, 2, 2, 2]; const str = 'aabbcccc'; const arr1 = str.split(''); console.log(Count(arr)); console.log(Count(arr1)); function Position(arr = [], val){ return arr.reduce((t, v, i) => (v === val && t.push(i), t), []) } console.log(Position(arr,2))