`$index = $next >= $links.length ? 0 : $next < 0 ? $links.length - 1 : $next;` and the following if can be removed