Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Created February 11, 2019 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amcdnl/5a84991f4cbcb7f50c6f5ad4f6b500de to your computer and use it in GitHub Desktop.
Save amcdnl/5a84991f4cbcb7f50c6f5ad4f6b500de to your computer and use it in GitHub Desktop.
// Problem: Create a UI that will display a list of fields
// that will have nesting based on dot notation...
// Example fields
const exampleFields = [
'name',
'description',
'entity.hostname',
'entity.url',
'entity.ipaddress.name',
'signal.url'
];
// Return results => [ { name: 'foo', children: [...] } ]
// const results = [];
// Given a field name, recurse to find parent
const recurse = (prop, parent) => {
const split = prop.split('.');
/*
if (split.length === 1) {
results.push(prop);
} else {
const [first, ...rest] = split;
const has =
}
*/
};
const results = exampleFields.reduce((acc, prop) => {
const [first, ...rest] = prop.split('.');
console.log(rest)
return acc;
}, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment