I need to count the repeated characters in such an example, get an array and return an object. Example: Input: [ 'a', 'b', 'a', 'v'] Output: {a: 2, b: 1, v:1}, the cycles may not be used, as well as mutations or rigid array value assignment within reduce. Now my code looks like this, but it doesn’t work.
(arr) => {
const arr2 = arr.filter((v, i, a) => a.indexOf(v) === i).map(v => [v, arr.filter(x => x === v).length
]) // [["a",2],["b",1],["v",1]]
const obj = Object.fromEntries(arr2)
return obj //undefined
}