【发布时间】:2019-12-10 12:47:04
【问题描述】:
我有以下 100% 工作的代码,但我不禁觉得它们是一种更好或更简单的编写方式,或者可能不是??所有的帮助总是感激的?? ??????
const entity: any = response.organisation;
if (Array.isArray(responseKey)) {
// responseKey e.g. ['site', 'accounts']
// I feel this two declarations can be refactored
const list = this.flattenGraphqlList<T>(entity[responseKey[0]][responseKey[1]]);
const {totalCount} = entity[responseKey[0]][responseKey[1]];
return {list, totalCount};
}
const list = this.flattenGraphqlList<T>(entity[responseKey]);
const {totalCount} = entity[responseKey];
return {list, totalCount};
【问题讨论】:
标签: javascript arrays indexing ecmascript-6 refactoring