Last active
August 29, 2015 14:15
-
-
Save joshblack/ee39634691b791cdcc2c to your computer and use it in GitHub Desktop.
List all the file paths!
This file contains hidden or 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
| // Given a certain object that represents a file system, create a function that | |
| // returns the path to every file in the system. | |
| // Assumptions: | |
| // * All keys are valid paths with a trailing slash. | |
| // * Values of keys can either be objects that represent folders, or they can be | |
| // an array of files. | |
| // * Every path terminates in an array containing a single file or multiple files. | |
| var path = { | |
| '/': { | |
| 'Users/': { | |
| 'Josh/': { | |
| 'Documents/': { | |
| 'Pictures/': ['pic1.jpg', 'pic2.jpg'] | |
| } | |
| }, | |
| 'David/': { | |
| 'Games/': ['League of Legends'] | |
| } | |
| } | |
| } | |
| }; | |
| console.log(yourFunction( /* params */ )); | |
| // Result: | |
| // [ '/Users/Josh/Documents/Pictures/pic1.jpg', | |
| // '/Users/Josh/Documents/Pictures/pic2.jpg' | |
| // '/Users/David/Games/League of Legends' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment