Last active
September 14, 2019 01:59
-
-
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)
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
(() => { | |
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