附件,23字节
{`~&>Zip[_,_[0:#_::0]]}
在线尝试!
说明
{`~&>Zip[_,_[0:#_::0]]}
{ } _: input (e.g., [5, 12, 10, 12, 12, 10])
0:#_ range from 0 to length of input (inclusive)
e.g., [0, 1, 2, 3, 4, 5, 6]
::0 descending range down to 0 for each element
e.g., [[0], [1, 0], [2, 1, 0], [3, 2, 1, 0], [4, 3, 2, 1, 0], [5, 4, 3, 2, 1, 0], [6, 5, 4, 3, 2, 1, 0]]
_[ ] get input elements at those indices
e.g., [[5], [12, 5], [10, 12, 5], [12, 10, 12, 5], [12, 12, 10, 12, 5], [10, 12, 12, 10, 12, 5], [nil, 10, 12, 12, 10, 12, 5]]
Zip[_, ] concatenate each value with this array
e.g., [[5, [5]], [12, [12, 5]], [10, [10, 12, 5]], [12, [12, 10, 12, 5]], [12, [12, 12, 10, 12, 5]], [10, [10, 12, 12, 10, 12, 5]]]
&> using each sub-array spread as arguments...
`~ count frequency
e.g. [12, [12, 10, 12, 5]] = 12 ~ [12, 10, 12, 5] = 2