Skip to content

Commit

Permalink
clean up loops with forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Mar 28, 2024
1 parent bd229f2 commit fd99cf5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/json-api-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,29 @@
if ('linked' in response) {
for (typeName in response.linked) {
linkedResources = response.linked[typeName];
for (j = 0, len1 = linkedResources.length; j < len1; j++) {
resourceData = linkedResources[j];
linkedResources.forEach((resourceData) => {
if (resourceData) {
this.type(typeName).create(resourceData, headers, response.meta);
}
}
});
}
}
results = [];
if ('data' in response) {
for (k = 0, len2 = response.data.length; k < len2; k++) {
resourceData = response.data[k];
response.data.forEach((resourceData) => {
if (resourceData) {
results.push(this.type(resourceData.type).create(resourceData, headers, response.meta));
}
}
});
} else {
for (typeName in response) {
resources = response[typeName];
if (indexOf.call(RESERVED_TOP_LEVEL_KEYS, typeName) < 0) {
for (l = 0, len3 = resources.length; l < len3; l++) {
resourceData = resources[l];
resources.forEach((resourceData) => {
if (resourceData) {
results.push(this.type(typeName).create(resourceData, headers, response.meta));
}
}
});
}
}
}
Expand Down

0 comments on commit fd99cf5

Please sign in to comment.