reduce(scenarios, (result, value, key) => { if (exceptIndex !== key && isNumber(value.weight)) { result = result - value.weight; return result; } else { return result; } }, 100)
const connect = (opts) => { const auth = authorization(opts) const env = environment(opts.production) return reduce(resources, (result, resource, key) => { result[key] = looper(result, resource, {auth, env}) return result }, {}) }
constructor(handlers = {}) { super(); this.handlers = {}; if (isObject(handlers)) { this.handlers = reduce(handlers, (carry, Handler, key) => { carry[key] = isFunction(Handler) ? new Handler() : Handler; // eslint-disable-line return carry; }, {}); } }
const toErrors = errors => reduce( errors.inner, (result, error) => { return { ...result, [error.path]: error.message }; }, {} )
export default function getMajorLanguage(languages) { const sumLinesOfCode = reduce((sum, linesOfCode) => sum + linesOfCode, 0)( languages, ) const highUsageLanguages = flow( pickBy((value, key) => (value > 10000 ? key : null)), keys, )(languages) const mostPopularLanguage = flow( mapValues((value, key) => value / sumLinesOfCode), obj => [keys(obj).reduce((a, b) => (obj[a] > obj[b] ? a : b), null)], filter(value => value), )(languages) return union([...highUsageLanguages, ...mostPopularLanguage]) }
const looper = (result, resource, authObject) => reduce(resource, (result, func, key) => { result[key] = isFunction(func) ? binder(func, authObject) : looper(result, func, authObject) return result }, {})
/** * Generate array of docker pull promises and wait until resolved to return merged output streams * TODO: this function should be depricated for pullImagesFromList, * as it couples too closely w/ the UI * @param {Object[]} comps array of computation objects to download * @param {String} comps.img Docker image name * @param {String} comp.compId Computation ID from app DB * @param {String} comp.compName Computation name from DB * @return {Object} Returns array of objects containing stream and computation parameters */ const pullImages = (comps) => { const compsP = reduce(comps, (arr, comp) => { arr.push(pullImage(`${comp.img}:latest`)); return arr; }, []); // Set promise catches to undefined so that failures can be handled as successes: https://davidwalsh.name/promises-results return Promise.all(compsP.map(prom => prom.catch(err => err))) .then((res) => { return comps.map((val, index) => ({ stream: res[index], compId: val.compId, compName: val.compName, })); }); }
reduce(languages, (result, language) => { const obj = result; obj[language] = requireTranslations(language); addLanguageLocaleData(language); return obj; }, {})
const all = (tree, collection) => reduce(collection, (result, item) => result && run(tree, item), true)
const appendImports = ({ fileNamesToInclude, source, alias }) => reduce( fileNamesToInclude, (existingImports, fileNameToInclude) => { return `${existingImports}\n @import "${alias}/${fileNameToInclude}.less";`; }, source, )
const and = elems => reduce(elems, (a, e) => a && e, true)
const any = (tree, collection) => reduce(collection, (result, item) => result || run(tree, item), false)
const any = (tree, collection) => reduce(collection, (result, item) => result || run(tree, item), false)
const all = (tree, collection) => reduce(collection, (result, item) => result && run(tree, item), true)
const and = elems => reduce(elems, (a, e) => a && e, true)