Given a list of strings, return an object that represents the tree structure.
getTree([
'src/main.js',
'src/second.js',
'src/components/header.js',
'src/components/helpers/sidebar.js'
]) -> {
"src": {
"main.js": "file",
"second.js": "file",
"components": {
"header.js": "file",
"helpers": {
"sidebar.js": "file",
},
}
}
}
function getTree(strings) {
// code
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
const arr = [
'src/main.js',
'src/second.js',
'src/components/header.js',
'src/components/helpers/sidebar.js'
];
const result = {
"src": {
"main.js": "file",
"second.js": "file",
"components": {
"header.js": "file",
"helpers": {
"sidebar.js": "file",
},
}
}
}
describe("Solution", function() {
it("should return object", function() {
assert.deepEqual(getTree(arr), result)
});
});