Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Javascript Tips: Add patterns for mapping and lookups #463

Open
josephjclark opened this issue Apr 2, 2024 · 0 comments
Open

Javascript Tips: Add patterns for mapping and lookups #463

josephjclark opened this issue Apr 2, 2024 · 0 comments

Comments

@josephjclark
Copy link
Contributor

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;
});
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant