System Design Leetcode Problems Javascript Foreach