Self Memoizing Function using closures