提交 d4ac7e90 编写于 作者: J Joao Moreno

arrays.index

上级 9c94be39
......@@ -232,4 +232,10 @@ export function fill<T>(num: number, valueFn: () => T, arr: T[] = []): T[] {
}
return arr;
}
export function index<T>(array: T[], indexer: (t: T) => string): { [key: string]: T; } {
const result = Object.create(null);
array.forEach(t => result[indexer(t)] = t);
return result;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册