Edit:
, , . .
@Bergi, Promises objects, .map(). , :
const getPromises = (objects) => {
return objects.map(object => new Parse.Promise.as()
.then(() => {
return destroy(object);
})
);
}
return Parse.Promise.when(getPromises(objects));
return Promise.all(getPromises(objects));
() , , .:)
for Array.forEach. .forEach(), , , for loops. , 99,99% . . .
.map() , , 1:1 20:20, Array , 20: 1 (: 20 1 ):
.map - use for 1:1 array transforms, as @bergi suggests.
.reduce - useful for transforming 1 array into ANYTHING else. Need a sum or subtotal? Or results grouped by day? Use .reduce().
.filter - return only items which result in a `true` result
.find - use to avoid full array scans when only 1 item must be returned.
.some - exit array scan returning true at first opportunity
let downloadedMsgs = emails.map(m => downloadBody(m))
let recipientsCount = emails.reduce((count, m) => count + m.to.length, 0)
let onlyRecentMsgs = emails.filter(m => m.isNew)
let aRecentMsg = emails.find(m => m.isNew)
let hasNewMessage = emails.some(m => m.isNew)
// (Notice last 3 identical predicate fn with different uses: aka pluripotency)
- Promises! , 100 , HTTP- ( ). Promises.