Skip to content

Commit 20c8e12

Browse files
committed
Fix reduce docs
1 parent 69c32da commit 20c8e12

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/cursor.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,11 @@ export class BatchedArrayCursor<T = any> {
506506
* { batchSize: 1 }
507507
* );
508508
* const result = await cursor.reduce((accumulator, currentBatch) => {
509-
* accumulator[
510-
* currentBatch[0] % 2 === 0 ? "even" : "odd"
511-
* ].push(...currentBatch);
509+
* if (currentBatch[0] % 2 === 0) {
510+
* accumulator.even.push(...currentBatch);
511+
* } else {
512+
* accumulator.odd.push(...currentBatch);
513+
* }
512514
* return accumulator;
513515
* }, { odd: [], even: [] });
514516
* console.log(result); // { odd: [1, 3, 5], even: [2, 4] }
@@ -517,7 +519,7 @@ export class BatchedArrayCursor<T = any> {
517519
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
518520
* const odd = [];
519521
* const even = [];
520-
* for await (const item of cursor) {
522+
* for await (const currentBatch of cursor) {
521523
* if (currentBatch[0] % 2 === 0) {
522524
* even.push(...currentBatch);
523525
* } else {
@@ -966,7 +968,11 @@ export class ArrayCursor<T = any> {
966968
* // BAD! NEEDLESSLY COMPLEX!
967969
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
968970
* const result = await cursor.reduce((accumulator, currentValue) => {
969-
* accumulator[currentValue % 2 === 0 ? "even" : "odd"].push(currentValue);
971+
* if (currentValue % 2 === 0) {
972+
* accumulator.even.push(...currentValue);
973+
* } else {
974+
* accumulator.odd.push(...currentValue);
975+
* }
970976
* return accumulator;
971977
* }, { odd: [], even: [] });
972978
* console.log(result); // { odd: [1, 3, 5], even: [2, 4] }
@@ -975,7 +981,7 @@ export class ArrayCursor<T = any> {
975981
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
976982
* const odd = [];
977983
* const even = [];
978-
* for await (const item of cursor) {
984+
* for await (const currentValue of cursor) {
979985
* if (currentValue % 2 === 0) {
980986
* even.push(currentValue);
981987
* } else {

0 commit comments

Comments
 (0)