File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments