Skip to content
New issue

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

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

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

No branches or pull requests

1 participant