Task:
Given an array of numbers as input (you can choose what subset, such as integers or natural numbers), replace all items with the number of times they appear within the array. As an example, [1, 2, 2, 1, 4, 8, 1]
would become [3, 2, 2, 3, 1, 1, 3]
.
You can take input/produce output as arrays, lists, tuples, or any other reasonable representation of some numbers.
Test cases:
[1] [1]
[1, 2] [1, 1]
[1, 1] [2, 2]
[1, 4, 4] [1, 2, 2]
[4, 4, 2] [2, 2, 1]
[4, 4, 4, 4] [4, 4, 4, 4]
[10, 20, 10, 20] [2, 2, 2, 2]
[1, 2, 2, 4, 4, 4, 4] [1, 2, 2, 4, 4, 4, 4]
[1, 2, 2, 1, 4, 8, 1] [3, 2, 2, 3, 1, 1, 3]
Other:
This is code-golf, shortest answer (in bytes) per language wins!
Ѐ
, Jelly would still have had a 2-byter inPọ
:P \$\endgroup\$