The input data is a two-dimensional array, in which each nested array will have two numeric values. The first will be the value to repeat, the second will be the number of repetitions of this value.
let repeatNumbers = function(data) { // Put your solution here }; console.log(repeatNumbers([[1, 10]])); console.log(repeatNumbers([[1, 2], [2, 3]])); console.log(repeatNumbers([[10, 4], [34, 6], [92, 2]]));
Expected Result:
1111111111 11, 222 10101010, 343434343434, 9292
The function must return a string in which each of the specified values is repeated a corresponding number of times, each set of values is separated by a comma. If there is only one set of values, skip the comma.
I only thought of a solution for the first subarray, how to decide when there are a lot of subarrays until I apply my mind (
let repeatNumbers = function(data) { let firstEl = data[0][0].toString(); return firstEl.repeat(data[0][1]); } console.log(repeatNumbers([[1, 10]])); console.log(repeatNumbers([[1, 2], [2, 3]])); console.log(repeatNumbers([[10, 4], [34, 6], [92, 2]]));