Tried to solve the problem with a recursive function, added console.time