Leetcode Time Limit Exceeded Javascript Array Filter By Index