Write a function generateOtp(random) that returns a random one-time password in the format of 'A23DR': one capital letter, two digits, then two capital letters.
A to Z, two digits from 0 to 9, two capital letters.random is a function that returns a number from 0 up to, but not including, 1, like Math.random(). If random is not given, use Math.random: function generateOtp(random = Math.random).random() exactly once for every character, from left to right, so 5 times in total.ALPHABET[Math.floor(random() * 26)], where ALPHABET is 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. For a digit take Math.floor(random() * 10). Math.floor cuts off the fraction.generateOtp(() => 0) returns 'A00AA', and generateOtp(() => 0.999) returns 'Z99ZZ'.Why a parameter: a test cannot know a random result in advance. With its own random, the test knows the exact answer. Without an argument the function stays random.
generateOtp(() => 0)Returns 'A00AA'
generateOtp(() => 0.5)Returns 'N55NN'
Asked at Luxoft · Source
Hidden tests run on Submit.