HackerEarth Interview Question

Design a polyfill for Array. flat()