HackerEarth interview question

Design a polyfill for Array. flat()