NOTE: This was a quick solve, should be tidied
Given an array of strings, produce an array of unique strings with max length of X
where the start of the string has as much of the string as possible - the end of the string is numbered.
inputX = ['Name A', 'Name A', 'Name B', 'Name C']
# process(inputX, maxLength8)
expected = ['Name A1','Name A2','Name B','Name C']
inputX = ['Name A', 'Name A', 'Name B', 'Name C']
# process(inputX, maxLength6)
expected = ['Name 1','Name 2','Name B','Name C']
-
Can run tests with
python test.py
-
Can import and use:
import scripty scripty.process(['abc', 'def'], 3)
- Cut the list to the max length
- Find unique items in the array and save them in results straight away
- If you got duplicates
- Generate a list of replacements with 1 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 2 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 3 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 4 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 5 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 6 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 7 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 8 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- Generate a list of replacements with 9 digit on the end
- Check if enough of those replacements aren't in the results already
- If you have enough, return the results
- If you've not got enough - go deeper
- If you run out of characters - cry 😭
- Return the results 🚀
- Party 🥳