Need to scrap the above padZeros, it’s flawed!!
const nums = [ 98, 25, 9, 36, 5, 9 ]
console.log(nums.map(padZeros))
// ['98', '25', '09', '036', '0005', '00009']
Stupid of me. The second argument passed by map, the index is being passed in as the second argument to padZeros the padding. I know this stuff and am now kicking myself. Another example of this is trying something like
nums.map(parseInt)
// [98, NaN, NaN, NaN, NaN, NaN]
In that instance the index is being passed to the radix
Lets have another go. lol
We could just do a pad to two function
const nums = [ 98, 25, 9, 36, 5, 9 ]
const padToTwo = (num) => num.toString().padStart(2, '0')
console.log(nums.map(padToTwo))
// ['98', '25', '09', '36', '05', '09']
Or if a little more adventurous a bit of manual currying
const nums = [ 98, 25, 9, 36, 5, 9 ]
// curry function
const padZeros = (pad) => (num) => num.toString().padStart(pad, '0')
const padToTwo = padZeros(2)
console.log(nums.map(padToTwo))
// ['98', '25', '09', '36', '05', '09']
const padToThree = padZeros(3)
console.log(nums.map(padToThree))
// ['098', '025', '009', '036', '005', '009']
Sorry about that.