While not likely to happen, maybe you should add an additional check here (&&) for count < 5  && $index < $predictions.length