Skip to content

Javascript Tips: Add patterns for mapping and lookups #463

Open
@josephjclark

Description

@josephjclark

The JS Tip section could use a bit about mapping and lookup patterns.

For mapping, I'd like to show example usage of array map and reduce, with short simple examples.

For lookups (dictionaries), I'd like to show a lookup pattern to map static values, functions or templates.

This is basically nonsense pseudocode but this is the sort of thing I want to show:

const map = {
   'static-key:' 'some-other-value',
   'dynamic-key': (v) => v.toUpperCase()
}

const mapped = patients.map((patient) => {
  const p = {};
  for (key of patient) {
   const mappedKey = map[key].(key)   ?? key;
   p[mappedKey] = map[patient[key]] ?? patient[key]
  }
 return p;
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions