I need help how to solve this logic in my JS code, for input - output flow same as I draw on the paper
Thanks in advance.
I need help how to solve this logic in my JS code, for input - output flow same as I draw on the paper
Thanks in advance.
Try like this:
const string = "123*123*123*123*123*66*55*32*32"
const arr = string.split("*")
const output = arr.reduce((prev, curr) => {
prev[curr] = (prev[curr]?? 0) + 1
return prev
}, {})
console.log(output)