Skip to content

Commit eaa28fe

Browse files
Style and comments.
1 parent bd06e77 commit eaa28fe

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/compiler/core.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,30 @@ module ts {
152152

153153
export function mapToArray<T>(map: Map<T>): T[] {
154154
var result: T[] = [];
155-
for (var id in map) result.push(map[id]);
155+
156+
for (var id in map) {
157+
result.push(map[id]);
158+
}
159+
156160
return result;
157161
}
158162

159-
export function arrayToMap<T>(array: T[], f: (value: T) => string): Map<T> {
163+
/**
164+
* Creates a map from the elements of an array.
165+
*
166+
* @param array the array of input elements.
167+
* @param makeKey a function that produces a key for a given element.
168+
*
169+
* This function makes no effort to avoid collisions; if any two elements produce
170+
* the same key with the given 'makeKey' function, then the element with the higher
171+
* index in the array will be the one associated with the produced key.
172+
*/
173+
export function arrayToMap<T>(array: T[], makeKey: (value: T) => string): Map<T> {
160174
var result: Map<T> = {};
161175

162-
forEach(array, value => { result[f(value)] = value });
176+
forEach(array, value => {
177+
result[makeKey(value)] = value
178+
});
163179

164180
return result;
165181
}

0 commit comments

Comments
 (0)