Skip to content

Instantly share code, notes, and snippets.

@ruslan-avantis
Last active June 2, 2023 10:13
Show Gist options
  • Save ruslan-avantis/2bc8fd96160b9a4fdabddcbbc512c503 to your computer and use it in GitHub Desktop.
Save ruslan-avantis/2bc8fd96160b9a4fdabddcbbc512c503 to your computer and use it in GitHub Desktop.
Example of working with arrays
const Promise = require('bluebird')
const items = {
employers: [
{
name: 'qqqq',
cost: 1111,
},
{
name: 'weferf',
cost: 2222,
}
]
}
// Promise.map
const getOne = async employers => {
let i = 0
return await Promise.map(employers, employer => {
const resp = {
i,
properties: employer
}
i++
return resp
}, { concurrency: 1 })
}
// Will return a new array
console.log('getOne: ', getOne(items.employers))
// Promise.filter
const filterEmployers = async (employers, filter) => {
return await Promise.filter(employers, employer => employer.cost === filter)
}
// Will return the filtered array
console.log('res2: ', getDuo(items.employers, 1111))
// array find
const findOne = (employers, find) => employers.find(employer => employer.cost === find)
// return object or undefined
console.log('findOne: ', findOne(items.employers, 1111))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment