Challenge #18 - numbers as strings

For this one, we’re given a list of customer numbers in challenge.dfl (11.2 KB)
like this:

Note that the customer ids are coming in as integer numbers.

Our target system requires customer numbers to come in as strings of length 8 with potential leading zeros.

Any number with more than 8 digits is treated as faulty and should be replaced with nil.

We’re looking to normalize the customer numbers so they look like this:

image

As a possible solution.dfl (19.8 KB) let’s have a look at the following:

  • Variable len stores the length of the currently processed customer number (when cast to string)

  • Variable padding_chars holds a helper function that given a number returns a list of as many"0" values, i.e. ["0", "0", "0"] when given 3.

  • Variable join holds a helper function that concatenates a list of strings with no separator.

  • Variable padding holds a helper function that returns a string of n zeros. We’re utilizing our previous helpers for implementation.

  • Finally the normalized variable definition contains the logic that maps incoming customer numbers to the required format. Nils and error values are mapped to nil, and customer numbers are padded if necessary. The result is always a string as per the variable type.

Remember that you can call or merely define functions from the UI. In this case, both padding_chars and join are not called, but merely defined such that we have a chance to utilize them in our calculations.