Skip to content

Commit

Permalink
Per cacjs#37: Make findLongest() be O(N), not O(NlogN)
Browse files Browse the repository at this point in the history
Probably doesn't make any practical difference, since this is only
used for the Command array, but less lines of code :-)

* src/utils.ts (findLongest)
  • Loading branch information
joaotavora committed Feb 19, 2021
1 parent f51fc22 commit de2edee
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ export const getMriOptions = (options: Option[]) => {
}

export const findLongest = (arr: string[]) => {
return arr.sort((a, b) => {
return a.length > b.length ? -1 : 1
})[0]
return arr.reduce((acc, a) => (a.length > acc.length ? a : acc))
}

export const padRight = (str: string, length: number) => {
Expand Down

0 comments on commit de2edee

Please sign in to comment.