Skip to content

Instantly share code, notes, and snippets.

@joshblack
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save joshblack/ee39634691b791cdcc2c to your computer and use it in GitHub Desktop.

Select an option

Save joshblack/ee39634691b791cdcc2c to your computer and use it in GitHub Desktop.
List all the file paths!
// 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