code is made of English letters, digits and dashes, with the dashes placed arbitrarily. You are also given a number size.
Rewrite the code as follows: remove every dash, turn every letter uppercase, then split the characters into groups joined by - so that each group has exactly size characters. Only the first group may be shorter, but it must not be empty. If the code has nothing but dashes, return an empty string.code="x7-k2p-9q", size=3 → 'X-7K2-P9Q'
Without dashes we have X7K2P9Q, 7 characters. Cutting groups of 3 from the end gives P9Q and 7K2, leaving X at the front.
code="ab-cd", size=4 → 'ABCD'
All four characters fit into a single group.
code="---", size=2 → ''
There is nothing but dashes, so the answer is an empty string.
code consists of English letters, digits and -code="x7-k2p-9q", size=3
'X-7K2-P9Q'
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.