Function mapRecord

  • Converts object to entries and map's it with provided callback.

    Type Parameters

    • K extends string | number | symbol
    • V
    • RK extends string | number | symbol
    • RV

    Parameters

    • obj: Record<K, V>

      Record like plain object

    • callback: ((entry) => [RK, RV])

      map callback, accepts entry pair ([key, value]) and should return entry pair

        • (entry): [RK, RV]
        • Parameters

          • entry: [K, V]

          Returns [RK, RV]

    Returns Record<RK, RV>

    new mapped object

    Example

    mapRecord({'a': 2}, ([k, v]) => [v, k * 2])
    >> {'b': 4}
    mapRecord({'a': 'b'}, ([k, v]) => [v, k])
    >> {'b': 'a'}