Prevent arrray.map returning undefined when condition