Last active
December 11, 2020 16:19
-
-
Save rvbsanjose/9eea352e141b4ccb5fe1f3bf18d513fc to your computer and use it in GitHub Desktop.
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
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