diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 24ce47333bb..7f43b726d16 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -152,14 +152,30 @@ module ts { export function mapToArray(map: Map): T[] { var result: T[] = []; - for (var id in map) result.push(map[id]); + + for (var id in map) { + result.push(map[id]); + } + return result; } - export function arrayToMap(array: T[], f: (value: T) => string): Map { + /** + * Creates a map from the elements of an array. + * + * @param array the array of input elements. + * @param makeKey a function that produces a key for a given element. + * + * This function makes no effort to avoid collisions; if any two elements produce + * the same key with the given 'makeKey' function, then the element with the higher + * index in the array will be the one associated with the produced key. + */ + export function arrayToMap(array: T[], makeKey: (value: T) => string): Map { var result: Map = {}; - forEach(array, value => { result[f(value)] = value }); + forEach(array, value => { + result[makeKey(value)] = value + }); return result; }