# Mapping, Filtering, and Reducing Things in an Array

**URL:** <https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057>\
**Category:** programming\
**Created:** [August 18, 2017, 2:04am UTC](https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057 "2017-08-18T02:04:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [August 18, 2017, 2:04am UTC](https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057/1 "2017-08-18T02:04:03Z")

</div>

This is the happening place to discuss what is going on with `map`, `filter`, and `reduce`: http://www.kirupa.com/html5/arrays\_map\_filter\_reduce.htm :slight\_smile:

---

<div class="post-metadata">

**Author:** ![alephpixel](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/alephpixel/32/9784_2.png) [@alephpixel](https://forum.kirupa.com/u/alephpixel)\
**Post date:** [July 26, 2019, 2:50pm UTC](https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057/2 "2019-07-26T14:50:52Z")

</div>

Hi kirupa!. There’s a typo on the code for the section “The old school way”. I thing it should be:

var names = [“marge”, “homer”, “bart”, “lisa”, “maggie”];  
var newNames = [];  
for (var i = 0; i \< names.length; i++) {  
var name = names[i];  
var firstLetter = name.charAt(0).toUpperCase();  
newNames.push(firstLetter + name.slice(1));  
}  
console.log(newNames);

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [July 26, 2019, 3:58pm UTC](https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057/3 "2019-07-26T15:58:58Z")

</div>

Thanks for pointing those mistakes out! It should be fixed now 🙂

```
var names = ["marge", "homer", "bart", "lisa", "maggie"];

var newNames = [];

for (var i = 0; i < names.length; i++) {
    var name = names[i];
    var firstLetter = name.charAt(0).toUpperCase();
    
    newNames.push(firstLetter + name.slice(1));
}

console.log(newNames);
```

---

<div class="post-metadata">

**Author:** ![emllew](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/emllew/32/13561_2.png) [@emllew](https://forum.kirupa.com/u/emllew)\
**Post date:** [February 8, 2021, 2:56pm UTC](https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057/4 "2021-02-08T14:56:59Z")

</div>

Hi Kirupa!

In “Getting One Value from an Array of Items”, how does the total become 31 using _reduce_?  
I thought reduce was simply adding the array up in this section’s example, like 1+2+3+4… etc, but I’ve tried by testing the code example in the console and it returns 78 so I’m not sure.

Thank you! 😄

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 8, 2021, 5:42pm UTC](https://forum.kirupa.com/t/mapping-filtering-and-reducing-things-in-an-array/637057/5 "2021-02-08T17:42:02Z")

</div>

@emllew - you are right! It is a bug in my version. It should be 78. I will fix the code in a few moments.
