Skip to content

Instantly share code, notes, and snippets.

@peekg
Last active September 14, 2019 01:59
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 peekg/637256445911d77773c7e1eb529be31b to your computer and use it in GitHub Desktop.
Save peekg/637256445911d77773c7e1eb529be31b to your computer and use it in GitHub Desktop.
Convert a list of paths, into an immutable map of maps (tree structure)
(() => {
const {Map, List} = require("immutable")
const list = List(
["archives",
"archives/arts",
"archives/history" ])
const tree = list.reduce( (map, it) => map.setIn( it.split( "/" ), Map() ), Map() )
list.map( path => assert.ok( tree.hasIn( path.split("/") ) ) )
assert.deepEqual( tree.toJS(), { "archives": { "arts": {}, "history": {} } } )
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment