collect.js
Advanced tools
Comparing version 3.0.40 to 3.0.43
'use strict'; | ||
module.exports = function get(key, defaultValue) { | ||
module.exports = function get(key) { | ||
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (this.items[key] !== undefined) { | ||
@@ -12,3 +14,7 @@ return this.items[key]; | ||
return defaultValue || null; | ||
if (defaultValue !== null) { | ||
return defaultValue; | ||
} | ||
return null; | ||
}; |
'use strict'; | ||
module.exports = function sum(key) { | ||
return this.items.reduce(function (accumulator, current) { | ||
if (key === undefined) { | ||
return accumulator + current; | ||
} else if (typeof key === 'function') { | ||
return accumulator + key(current); | ||
var total = 0; | ||
if (key === undefined) { | ||
for (var i = 0; i < this.items.length; i += 1) { | ||
total += this.items[i]; | ||
} | ||
} else if (typeof key === 'function') { | ||
for (var _i = 0; _i < this.items.length; _i += 1) { | ||
total += key(this.items[_i]); | ||
} | ||
} else { | ||
for (var _i2 = 0; _i2 < this.items.length; _i2 += 1) { | ||
total += this.items[_i2][key]; | ||
} | ||
} | ||
return accumulator + current[key]; | ||
}, 0); | ||
return total; | ||
}; |
{ | ||
"name": "collect.js", | ||
"version": "3.0.40", | ||
"version": "3.0.43", | ||
"description": "Convenient and dependency free wrapper for working with arrays and objects.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
'use strict'; | ||
module.exports = function get(key, defaultValue) { | ||
module.exports = function get(key, defaultValue = null) { | ||
if (this.items[key] !== undefined) { | ||
@@ -12,3 +12,7 @@ return this.items[key]; | ||
return defaultValue || null; | ||
if (defaultValue !== null) { | ||
return defaultValue; | ||
} | ||
return null; | ||
}; |
'use strict'; | ||
module.exports = function sum(key) { | ||
return this.items.reduce((accumulator, current) => { | ||
if (key === undefined) { | ||
return accumulator + current; | ||
} else if (typeof key === 'function') { | ||
return accumulator + key(current); | ||
let total = 0; | ||
if (key === undefined) { | ||
for (let i = 0; i < this.items.length; i += 1) { | ||
total += this.items[i]; | ||
} | ||
} else if (typeof key === 'function') { | ||
for (let i = 0; i < this.items.length; i += 1) { | ||
total += key(this.items[i]); | ||
} | ||
} else { | ||
for (let i = 0; i < this.items.length; i += 1) { | ||
total += this.items[i][key]; | ||
} | ||
} | ||
return accumulator + current[key]; | ||
}, 0); | ||
return total; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232140
2468