Use reduce() instead of forEach() for building KeyValueIndex

This commit is contained in:
haad 2016-05-04 11:30:37 +02:00
parent 3c4fc90819
commit d823ab4d2b

View File

@ -10,9 +10,7 @@ class KeyValueIndex {
} }
updateIndex(oplog, updated) { updateIndex(oplog, updated) {
let handled = []; updated.reverse().reduce((handled, item) => {
updated.reverse().forEach((item) => {
if(handled.indexOf(item.key) === -1) { if(handled.indexOf(item.key) === -1) {
handled.push(item.key); handled.push(item.key);
if(item.op === 'PUT') { if(item.op === 'PUT') {
@ -21,7 +19,8 @@ class KeyValueIndex {
delete this._index[item.key]; delete this._index[item.key];
} }
} }
}); return handled;
}, []);
} }
} }