Commit 7429c4c8 authored by mo khan's avatar mo khan

Attempt to make reduction easier to read

parent 127f29c4
...@@ -17,25 +17,20 @@ class V2Report { ...@@ -17,25 +17,20 @@ class V2Report {
} }
combine(licenses, visitor) { combine(licenses, visitor) {
return licenses.reduce( const reducer = (memo, licenseId) => {
(memo, licenseId) => {
const license = this.licenseMap[licenseId]; const license = this.licenseMap[licenseId];
visitor(license); visitor(license);
if (memo.name === null) { if (memo)
return {
name: license.name,
url: license.url,
};
}
return { name: `${memo.name}, ${license.name}`, url: '' }; return { name: `${memo.name}, ${license.name}`, url: '' };
}, return { name: license.name, url: license.url };
{ name: null, url: null }, };
);
return licenses.reduce(reducer, null);
} }
incrementCountFor(licenseName) { incrementCountFor(licenseName) {
const license = this.licenses.find(license => license.name === licenseName); const matchingLicense = this.licenses.find(license => license.name === licenseName);
if (license) license.count += 1; if (matchingLicense) matchingLicense.count += 1;
} }
mapFromDependency(dependency) { mapFromDependency(dependency) {
...@@ -58,10 +53,11 @@ class V2Report { ...@@ -58,10 +53,11 @@ class V2Report {
} }
static createLicenseMap(licenses) { static createLicenseMap(licenses) {
return licenses.reduce((memo, item) => { const reducer = (memo, item) => {
memo[item.id] = { name: item.name, url: item.url }; // eslint-disable-line no-param-reassign memo[item.id] = { name: item.name, url: item.url }; // eslint-disable-line no-param-reassign
return memo; return memo;
}, {}); };
return licenses.reduce(reducer, {});
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment