Refactor number_match_count, using inject and ternary operation