From abf926b4ef7d9c97ed89327dec8e88020bc69f0a Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Mon, 18 Dec 2017 08:33:35 +0530 Subject: [PATCH] Update sqaure_it.md --- snippets/sqaure_it.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/sqaure_it.md b/snippets/sqaure_it.md index 665932e3d..eed3eb137 100644 --- a/snippets/sqaure_it.md +++ b/snippets/sqaure_it.md @@ -1,6 +1,8 @@ ### Square The Data -Use mapObject to return a object from array passed as an argument which gets sqaured as math operation +Using an anonymous inner function scope we declare an undefined memory space using closures for storing a return value. We then use a new Array to store the array with a map of the function over it's data set and a comma operator to return a second step without needing to move from one context to another thank to closures and order of operations. + +Notice the need to declare an order of operations(parenthesis) around the anonymous inner function so we can call it immediately. ```js const mapObject = (arr, fn) => (a => (a = [arr, arr.map(fn)], a[0].reduce( (acc,val,ind) => (acc[val] = a[1][ind], acc), {}) )) ( )