INNER CODE UNIT · JavaScript
addAll
pegaltier/awesome-utils-dev · utils-script/jsfunctions.js:17
function addAll(target, source) {
const errors = [];
if (target instanceof Map) {
Array.from(source.entries()).forEach(it => target.has(it[0]) ? target.set(it[0], it[1]) : errors.push(it))
} else if (target instanceof Set) {
source.forEach(it => target.has(it[0]) ? target.add(it) : errors.push(it))
}
if (errors.length) {
console.error('addAll() ~ source contains incorrect timestamp', errors);
}
}
// https://stackoverflow.com/questions/14446511/most-efficient-method-to-groupby-on-an-array-of-objects
const groupBy = (x,f)=>x.reduce((a,b,i)=>((a[f(b,i,x)]||=[]).push(b),a),{});
// https://advancedweb.hu/how-to-use-async-functions-with-array-map-in-javascript/
const mapInGroups = (arr, iteratee, groupSize) => {