Suppose there is a string aba and a limit 5. How can i create an array with elements repeating from the string till the limit is reached ?
e.g. string = "aba" and limit = 5 will give new array ["a","b","a","a","b"]
As of now, my array fills with all characters then blank strings are repeated for the left indexes.
function repeatedString(s, n) {
let arr = [];
for (let i = 0; i < n; i++) {
let char = s.charAt(i);
arr.push(char);
}
console.log(arr);
}
repeatedString("aba", 5)