Skip to content

Instantly share code, notes, and snippets.

@rvbsanjose
Last active December 11, 2020 16:19
Show Gist options
  • Save rvbsanjose/9eea352e141b4ccb5fe1f3bf18d513fc to your computer and use it in GitHub Desktop.
Save rvbsanjose/9eea352e141b4ccb5fe1f3bf18d513fc to your computer and use it in GitHub Desktop.
const lengthLongestPath = input => {
return input.split('\n').reduce((os, path) => {
const idx = path.lastIndexOf('\t') + 1;
idx <= os.filePath.length && os.filePath.splice(idx);
os.filePath.push(path.slice(idx));
if (path.lastIndexOf('.') >= 0) {
const length = os.filePath.join('/').length;
os.longest = length > os.longest ? length : os.longest;
}
return os;
}, { filePath: [], longest: 0 }).longest;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment