Let's walk through what your code currently does, which is often a good way to find any problems.
let day = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
This creates your days of the week array in an outer scope.
function repeatArray(day, count) {
This declares the repeatArray function -- which shadows the "day" variable. Since it has the same name as the "day" array in the global scope, anything inside this function that references "day" will reference this argument and you will have no access to the outer array.
var ln = day.length;
var b = new Array();
var a = new Array();
ln is now the length of the first argument passed to the function. b and a are empty arrays.
for (i = 0; i < count; i++) {
day.push(day[i % ln]);
}
This pushes to the first argument the value in the first argument, at the position i mod ln, for all i from 0 to count. So if the first argument is the array ['a', 'b', 'c'], and count is 6, it would be pushing 'a', 'b', 'c', 'a', 'b', 'c' to the first argument, resulting in the array ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']. I don't think this is what you want. But let's continue.
return b;
The function returns b, which is still just a new, empty array with nothing in it, since we haven't touched it.
var a = new Array();
a.push("test1");
a.push("test2");
a.push("test3");
This creates an array, a, which ends up being ['test1', 'test2', 'test3'].
var b = repeatArray(a, 13);
console.log(b.length);
In our function call, 'day' will be the array a (so ['test1', 'test2', 'test3']), and count will be 13. Since the function returns an empty array every time, the length will always be 0. The array a, however, will be modified to repeat 'test1', 'test2', 'test3' 13 extra times, making its length 16 (13 plus the initial 3 values).
For your task, you don't need that kind of repetition or to create a new array. You can just use modular math :)
let day = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
function daysAfter(initial, n) {
const initialIndex = day.indexOf(initial);
return day[(initialIndex + n) % day.length];
}
So now daysAfter('wednesday', 13) will equal tuesday as expected :)
day.pushshouldn't beb.push? Since you createbbut never uses it and then you return it... also I would suggest to change thelet dayto another name to not mess names with parameterdayas andbs and it makes it harder to reason about what's in whichafor example. When you're just starting out, making everything named uniquely and meaningfully will make it harder to introduce meaningless variables (like thebvariable in your function. Also note thatdayis an array of day names, but also the name of an argument to your function; useconsole.log(day)at the top of your function and you may be surprised by what it contains. I encourage you to use a debugger to step through your code