Is there an easy way to separate values in an array of random numbers between 0-99 based on their first and second digits? I need two arrays: one for values that share the same first digit, and another for values that share the same second digit. The actual digit value doesn't matter; as long as it is repeated within a number. Just to clarify, the digits 0-9 should be treated as if the first digit was 0.
For example, given the array:
[0, 10, 20, 11, 19, 12, 54, 64, 23, 24]
, the resulting arrays would be: [10, 11, 12, 19, 23, 24]
and [0, 10, 20, 24, 54, 64]
. Some values can appear in both arrays if they meet the specified criteria.
I have come across solutions that work when you know the specific digit you are looking for, but in this case, I am unsure how to proceed.
One suggested approach is to convert the numbers in the array into strings using array.map(String)
, so that the first and second digits can be accessed as first[0]
and second[1]
. However, I am unsure about the next steps. Any suggestions would be greatly appreciated.