You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**dogNames** shows the dog names from the array of objects; **sayHi** concatenates "Hello" and each of the dog names; and **mapObject**creates another array of objects.
203
+
**dogNames** shows the dog names from the array of objects; **sayHi** concatenates "Hello" and each of the dog names; **mapArray**and **mapArrayIndex**create another two arrays of objects.
202
204
203
205
## mapValues
204
206
@@ -287,6 +289,7 @@ var dogs = [
287
289
var ages = map(dogs, dog => dog.age)
288
290
output totalAge int = reduce(ages, 0, (cur, next) => cur + next)
289
291
output totalAgeAdd1 int = reduce(ages, 1, (cur, next) => cur + next)
292
+
output oddAge int = reduce(ages, 0, (cur, next, i) => (i % 2 == 0) ? cur + next : cur)
290
293
```
291
294
292
295
The output from the preceding example is:
@@ -295,8 +298,9 @@ The output from the preceding example is:
295
298
| ---- | ---- | ----- |
296
299
| totalAge | int | 18 |
297
300
| totalAgeAdd1 | int | 19 |
301
+
| oddAge | int | 7 |
298
302
299
-
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.
303
+
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.**oddAge** sums the ages of dogs that are located at even indices, specifically **5** (Evie) and **2** (Indy).
**dogNames** shows the dog names from the array of objects; **sayHi** concatenates "Hello" and each of the dog names; and **mapObject**creates another array of objects.
284
+
**dogNames** shows the dog names from the array of objects; **sayHi** concatenates "Hello" and each of the dog names; **mapArray**and **mapArrayIndex**create another two arrays of objects.
280
285
281
286
## mapValues
282
287
@@ -400,6 +405,10 @@ The following examples show how to use the `reduce` function.
@@ -411,8 +420,9 @@ The output from the preceding example is:
411
420
| ---- | ---- | ----- |
412
421
| totalAge | int | 18 |
413
422
| totalAgeAdd1 | int | 19 |
423
+
| oddAge | int | 7 |
414
424
415
-
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.
425
+
**totalAge** sums the ages of the dogs; **totalAgeAdd1** has an initial value of 1, and adds all the dog ages to the initial values.**oddAge** sums the ages of dogs that are located at even indices, specifically **5** (Evie) and **2** (Indy).
0 commit comments