Holey Sort

Published by Mubashir Hassan in

What do the numbers 4, 6, 8, 9 and 0 have in common? They all have holes in them! Notice how the number 8 contains not one, but two holes.

Given an array of numbers, sort the array in accordance to how many holes occur in the number. It should be sorted in ascending order.

Examples

holeySort([44, 4, 444, 4444]) ➞ [4, 44, 444, 4444]

holeySort([100, 888, 1660, 11]) ➞ [11, 100, 1660, 888]

holeySort([8, 121, 41, 66]) ➞ [121, 41, 8, 66]

Notes

  • If two numbers have the same number of holes in them, sort them by the order they first appeared in.
  • Despite the number 0 appearing to have two holes in certain fonts, it will only have one hole for the purposes of this challenge.
Watch a quick demo on how Edabit works.