Skip to content

Commit

Permalink
Remove usage of lodash _.indexOf.
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 485d97c commit 58e75f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scan/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace chevrotain {
let longerAltClass = clazz.LONGER_ALT

if (longerAltClass) {
let longerAltIdx = _.indexOf(onlyRelevantClasses, longerAltClass)
let longerAltIdx = utils.indexOf(onlyRelevantClasses, longerAltClass)
return longerAltIdx
}
})
Expand Down
9 changes: 9 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,13 @@ namespace chevrotain.utils {
}
return false
}

export function indexOf<T>(arr:T[], value:T):number {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === value) {
return i
}
}
return -1
}
}
8 changes: 7 additions & 1 deletion test/utils/utils_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ namespace chevrotain.utils.spec {
expect(some([1, 2, 3], (item) => {return item % 2 === 0})).to.be.true
expect(some([1, 3, 5], (item) => {return item % 2 === 0})).to.be.false
})

it("exports an indexOf utility", () => {
expect(indexOf([1, 2, 3], 2)).to.equal(1)
expect(indexOf([1, 2, 3], 3)).to.equal(2)
expect(indexOf([1, 2, 3], 0)).to.equal(-1)
expect(indexOf([], -2)).to.equal(-1)
})
})
}

0 comments on commit 58e75f3

Please sign in to comment.