From eaa28feefd95875919d92401fffb95a9b3ab9342 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 6 Aug 2014 14:29:43 -0700 Subject: [PATCH] Style and comments. --- src/compiler/core.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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; }