docs
docs copied to clipboard
Javascript Tips: Add patterns for mapping and lookups
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;
});