Skip to content

add fn itemsToDict #2

@puiutucutu

Description

@puiutucutu
/**
 * Creates an object where each string from the array of strings is the object
 * key set to some default value.
 *
 * @param {*} defaultValue
 * @return {function(xs: string[]): Object}
 * @example
 *
 * itemsToDict(null)(["a","b","c"]); //=> { a: null, b: null, c: null }
 *
 */
export const itemsToDict = defaultValue => xs => {
  return xs.reduce((acc, x) => ((acc[x] = defaultValue), acc), {});
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions