From 973ceb92da7bf49b55c9dad4b939fdf665b4443c Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Wed, 8 Jan 2020 18:35:14 +0300 Subject: [PATCH] Add @ as map operation prefix --- reduce.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reduce.js b/reduce.js index 6f6a880..f5b0419 100644 --- a/reduce.js +++ b/reduce.js @@ -13,6 +13,12 @@ function reduce(json, code) { return Object.keys(json) } + if (/^@/.test(code)) { + return eval(`function fn() { + return Object.values(this).map(x => x${code.substring(1)}) + }; fn`).call(json) + } + if (/^\.\[/.test(code)) { return eval(`function fn() { return this${code.substring(1)}