collect.js
Advanced tools
Comparing version 3.0.52 to 3.1.0
'use strict'; | ||
module.exports = function flatMap(fn) { | ||
var _this = this; | ||
var items = []; | ||
var values = []; | ||
this.items.forEach(function (childObject, index) { | ||
var keys = Object.keys(childObject); | ||
var values = []; | ||
Object.keys(this.items).forEach(function (property) { | ||
values.push(_this.items[property]); | ||
}); | ||
keys.forEach(function (prop) { | ||
values.push(childObject[prop]); | ||
}); | ||
var newValues = fn(values); | ||
var mapped = fn(values, index); | ||
var collection = {}; | ||
var collection = {}; | ||
Object.keys(this.items).forEach(function (value, index) { | ||
collection[value] = newValues[index]; | ||
keys.forEach(function (key, i) { | ||
collection[key] = mapped[i]; | ||
}); | ||
items.push(collection); | ||
}); | ||
return new this.constructor(collection); | ||
return new this.constructor(Object.assign.apply(Object, items)); | ||
}; |
{ | ||
"name": "collect.js", | ||
"version": "3.0.52", | ||
"version": "3.1.0", | ||
"description": "Convenient and dependency free wrapper for working with arrays and objects.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -455,7 +455,7 @@ # <img src="https://raw.githubusercontent.com/ecrmnn/collect.js/master/collectjs.jpg" alt="collect.js"> | ||
```js | ||
const collection = collect({ | ||
name: 'Robbie Fowler', | ||
nickname: 'The God', | ||
position: 'Striker' | ||
}); | ||
const collection = collect([ | ||
{ name: 'Robbie Fowler' }, | ||
{ nickname: 'The God' }, | ||
{ position: 'Striker' }, | ||
]); | ||
@@ -462,0 +462,0 @@ const flatMapped = collection.flatMap(function (values) { |
'use strict'; | ||
module.exports = function flatMap(fn) { | ||
const values = []; | ||
const items = []; | ||
Object.keys(this.items).forEach((property) => { | ||
values.push(this.items[property]); | ||
}); | ||
this.items.forEach((childObject, index) => { | ||
const keys = Object.keys(childObject); | ||
const values = []; | ||
const newValues = fn(values); | ||
keys.forEach((prop) => { | ||
values.push(childObject[prop]); | ||
}); | ||
const collection = {}; | ||
const mapped = fn(values, index); | ||
Object.keys(this.items).forEach((value, index) => { | ||
collection[value] = newValues[index]; | ||
const collection = {}; | ||
keys.forEach((key, i) => { | ||
collection[key] = mapped[i]; | ||
}); | ||
items.push(collection); | ||
}); | ||
return new this.constructor(collection); | ||
return new this.constructor(Object.assign(...items)); | ||
}; |
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
242326
2533