Created
August 30, 2021 15:39
-
-
Save krisalyssa/3289681eff899fcc7f0eef40851c02d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var __importDefault = (this && this.__importDefault) || function (mod) { | |
return (mod && mod.__esModule) ? mod : { "default": mod }; | |
}; | |
exports.__esModule = true; | |
var reduce_1 = __importDefault(require("lodash/reduce")); | |
function testReduction() { | |
var tempArray = [ | |
{ a: 'foo', b: 'bar' }, | |
{ a: 'baz', b: 'quux' } | |
]; | |
var reduction = reduce_1["default"](tempArray, function (acc, value) { | |
console.log("value: a='" + value.a + "', b='" + value.b + "'"); | |
console.log("acc before=" + JSON.stringify(acc)); | |
var newAcc = acc.set(value.a, value); | |
console.log("acc after=" + JSON.stringify(acc)); | |
console.log("newAcc=" + JSON.stringify(newAcc)); | |
return acc; | |
}, new Map()); | |
console.log("reduction=" + JSON.stringify(reduction)); | |
} | |
testReduction(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import reduce from 'lodash/reduce' | |
type ReductionTest = { | |
a: string | |
b: string | |
} | |
function testReduction () { | |
const tempArray: ReductionTest[] = [ | |
{ a: 'foo', b: 'bar' }, | |
{ a: 'baz', b: 'quux' } | |
] | |
const reduction = reduce( | |
tempArray, | |
(acc: Map<string, ReductionTest>, value: ReductionTest) => { | |
console.log(`value: a='${value.a}', b='${value.b}'`) | |
console.log(`acc before=${JSON.stringify(acc)}`) | |
const newAcc = acc.set(value.a, value) | |
console.log(`acc after=${JSON.stringify(acc)}`) | |
console.log(`newAcc=${JSON.stringify(newAcc)}`) | |
return acc | |
}, | |
new Map<string, ReductionTest>() | |
) | |
console.log(`reduction=${JSON.stringify(reduction)}`) | |
} | |
testReduction() |
Author
krisalyssa
commented
Aug 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment