Domanda di colloquio di Altimetrik

Flatten the given array [1, [2, [3, [4]], 5]] without using inbuilt flat() function?