Skip to content

Commit

Permalink
Remove usage of lodash _.zipObject.
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 2c49431 commit 4e05a8c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scan/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace chevrotain {
return addStartOfInput(currClass[PATTERN])
})

let allPatternsToClass = _.zipObject(<any>allTransformedPatterns, onlyRelevantClasses)
let allPatternsToClass = utils.zipObject(<any>allTransformedPatterns, onlyRelevantClasses)

let patternIdxToClass:any = utils.map(allTransformedPatterns, (pattern) => {
return allPatternsToClass[pattern.toString()]
Expand Down
12 changes: 12 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,16 @@ namespace chevrotain.utils {
result.sort((a, b) => orderFunc(a) - orderFunc(b))
return result
}

export function zipObject(keys:any[], values:any[]):Object {
if (keys.length !== values.length) {
throw Error("can't zipObject with different number of keys and values!")
}

let result = {}
for (let i = 0; i < keys.length; i++) {
result[keys[i]] = values[i]
}
return result
}
}
5 changes: 5 additions & 0 deletions test/utils/utils_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ namespace chevrotain.utils.spec {
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])
})

it("exports a zipObject utility", () => {
expect(zipObject(["ima", "aba", "bamba"], [1, 2, 3])).to.deep.equal({"ima": 1, "aba": 2, "bamba": 3})
expect(() => zipObject(["ima", "aba"], [1, 2, 3])).to.throw("can't zipObject")
expect(zipObject([], [])).to.deep.equal({})
})
})
}

0 comments on commit 4e05a8c

Please sign in to comment.