Two Out Of Three Leetcode Javascript