Js counts the number of spaces

var a = ["a", "b", "c", ""]; the calculated result of
is
{

.
a:3,
b:2,
c:1

}

Mar.21,2022

var a = ['a', '', '', '', 'b', '', '', 'c', ''];

let b = a.reduce((d, v) => void (v ? (d.k = v) && (d.v[v] = 0) : d.v[d.k] += 1) || d, {v: {}, k: ''}).v;

console.log(b);

((a, _) => a.reduce((p, c) => 
[_ = c || _, _ && [p[_] = p[_] || 0, !c && (p[_] PP)], p][2], {}))
(["a","","","","b","","","c",""], undefined)

ignores all empty characters before the first non-null character.

Menu