Toptal interview question

code a memoizing function