File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -152,14 +152,30 @@ module ts {
152
152
153
153
export function mapToArray < T > ( map : Map < T > ) : T [ ] {
154
154
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
+
156
160
return result ;
157
161
}
158
162
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 > {
160
174
var result : Map < T > = { } ;
161
175
162
- forEach ( array , value => { result [ f ( value ) ] = value } ) ;
176
+ forEach ( array , value => {
177
+ result [ makeKey ( value ) ] = value
178
+ } ) ;
163
179
164
180
return result ;
165
181
}
You can’t perform that action at this time.
0 commit comments