Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Indexed: function reduce(iterable, reducer, initial) {
let reduced;
if (arguments.length > 2) {
reduced = reduceIterable(initial, reducer, iterable);
} else {
reduced = reduceIterable(reducer, iterable);
}
return reduced;
},
Keyed: function reduce(iterable, reducer, initial) {
Duplicated: function reduce(iterable, reducer, initial) {
const setReducer = (acc, item) => reducer(acc, item, item);
let reduced;
if (arguments.length > 2) {
reduced = reduceIterable(initial, setReducer, iterable);
} else {
reduced = reduceIterable(setReducer, iterable);
}
return reduced;
},
Indexed: function reduce(iterable, reducer, initial) {
Keyed: function reduce(iterable, reducer, initial) {
let invocations = 0;
let hasInitial = arguments.length > 2;
let reduced;
const keyedReducer = (acc, [key, value]) => {
if (invocations++ === 0 && !hasInitial) {
acc = acc[1];
}
return reducer(acc, value, key);
};
if (hasInitial) {
reduced = reduceIterable(initial, keyedReducer, iterable);
} else {
reduced = reduceIterable(keyedReducer, iterable);
}
return reduced;
},
};
Keyed: function reduce(iterable, reducer, initial) {
let invocations = 0;
let hasInitial = arguments.length > 2;
let reduced;
const keyedReducer = (acc, [key, value]) => {
if (invocations++ === 0 && !hasInitial) {
acc = acc[1];
}
return reducer(acc, value, key);
};
if (hasInitial) {
reduced = reduceIterable(initial, keyedReducer, iterable);
} else {
reduced = reduceIterable(keyedReducer, iterable);
}
return reduced;
},
};
Indexed: function reduce(iterable, reducer, initial) {
let reduced;
if (arguments.length > 2) {
reduced = reduceIterable(initial, reducer, iterable);
} else {
reduced = reduceIterable(reducer, iterable);
}
return reduced;
},
Keyed: function reduce(iterable, reducer, initial) {
Duplicated: function reduce(iterable, reducer, initial) {
const setReducer = (acc, item) => reducer(acc, item, item);
let reduced;
if (arguments.length > 2) {
reduced = reduceIterable(initial, setReducer, iterable);
} else {
reduced = reduceIterable(setReducer, iterable);
}
return reduced;
},
Indexed: function reduce(iterable, reducer, initial) {