Created
February 11, 2019 17:22
-
-
Save amcdnl/5a84991f4cbcb7f50c6f5ad4f6b500de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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