Skip to content

Commit

Permalink
Remove usage of lodash _.sortBy.
Browse files Browse the repository at this point in the history
Relates to #68.
  • Loading branch information
Shahar Soel committed Jan 10, 2016
1 parent 2aa52ef commit 2c49431
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/lang/lang_extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ namespace chevrotain.lang {
containsKey(key:string):boolean {
return utils.has(this._state, key)
}

}

}



2 changes: 1 addition & 1 deletion src/parse/gast_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace chevrotain.gastBuilder {
topLevelRange:r.IRange,
allRanges:IProdRange[]):T {
let secondLevelProds = getDirectlyContainedRanges(topLevelRange, allRanges)
let secondLevelInOrder = _.sortBy(secondLevelProds, (prodRng) => { return prodRng.range.start })
let secondLevelInOrder = utils.sortBy(secondLevelProds, (prodRng) => { return prodRng.range.start })

let definition:gast.IProduction[] = []
utils.forEach(secondLevelInOrder, (prodRng) => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,10 @@ namespace chevrotain.utils {
}
return -1
}

export function sortBy<T>(arr:T[], orderFunc:(item:T) => number):T[] {
let result = cloneArr(arr)
result.sort((a, b) => orderFunc(a) - orderFunc(b))
return result
}
}
6 changes: 6 additions & 0 deletions test/utils/utils_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,11 @@ namespace chevrotain.utils.spec {
expect(indexOf([1, 2, 3], 0)).to.equal(-1)
expect(indexOf([], -2)).to.equal(-1)
})

it("exports a sortBy utility", () => {
expect(sortBy([1, 2, 3], (num) => num)).to.deep.equal([1, 2, 3])
expect(sortBy([3, 2, 1], (num) => num)).to.deep.equal([1, 2, 3])

})
})
}

0 comments on commit 2c49431

Please sign in to comment.