freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-an.../functional-programming/use-the-reduce-method-to-an...

346 lines
13 KiB
Markdown
Raw Normal View History

---
id: 587d7da9367417b2b2512b68
title: Use the reduce Method to Analyze Data
challengeType: 1
forumTopicId: 301313
dashedName: use-the-reduce-method-to-analyze-data
---
# --description--
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
`Array.prototype.reduce()`, or simply `reduce()`, is the most general of all array operations in JavaScript. You can solve almost any array processing problem using the `reduce` method.
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
The `reduce` method allows for more general forms of array processing, and it's possible to show that both `filter` and `map` can be derived as special applications of `reduce`. The `reduce` method iterates over each item in an array and returns a single value (i.e. string, number, object, array). This is achieved via a callback function that is called on each iteration.
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
The callback function accepts four arguments. The first argument is known as the accumulator, which gets assigned the return value of the callback function from the previous iteration, the second is the current element being processed, the third is the index of that element and the fourth is the array upon which `reduce` is called.
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
In addition to the callback function, `reduce` has an additional parameter which takes an initial value for the accumulator. If this second parameter is not used, then the first iteration is skipped and the second iteration gets passed the first element of the array as the accumulator.
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
See below for an example using `reduce` on the `users` array to return the sum of all the users' ages. For simplicity, the example only uses the first and second arguments.
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
```js
const users = [
{ name: 'John', age: 34 },
{ name: 'Amy', age: 20 },
{ name: 'camperCat', age: 10 }
];
const sumOfAges = users.reduce((sum, user) => sum + user.age, 0);
chore(learn): audit javascript algorithms and data structures (#41092) * chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-03 00:12:12 +00:00
console.log(sumOfAges);
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
```
chore(learn): audit javascript algorithms and data structures (#41092) * chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-03 00:12:12 +00:00
The console would display the value `64`.
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
In another example, see how an object can be returned containing the names of the users as properties with their ages as values.
```js
const users = [
{ name: 'John', age: 34 },
{ name: 'Amy', age: 20 },
{ name: 'camperCat', age: 10 }
];
const usersObj = users.reduce((obj, user) => {
obj[user.name] = user.age;
return obj;
}, {});
chore(learn): audit javascript algorithms and data structures (#41092) * chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-03 00:12:12 +00:00
console.log(usersObj);
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
```
chore(learn): audit javascript algorithms and data structures (#41092) * chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-03 00:12:12 +00:00
The console would display the value `{ John: 34, Amy: 20, camperCat: 10 }`.
# --instructions--
chore(learn): audit javascript algorithms and data structures (#41092) * chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-03 00:12:12 +00:00
The variable `watchList` holds an array of objects with information on several movies. Use `reduce` to find the average IMDB rating of the movies directed by `Christopher Nolan`. Recall from prior challenges how to `filter` data and `map` over it to pull what you need. You may need to create other variables, and return the average rating from `getRating` function. Note that the rating values are saved as strings in the object and need to be converted into numbers before they are used in any mathematical operations.
# --hints--
The `watchList` variable should not change.
```js
assert(
watchList[0].Title === 'Inception' && watchList[4].Director == 'James Cameron'
);
```
Your code should use the `reduce` method.
```js
assert(code.match(/\.reduce/g));
```
The `getRating(watchList)` should equal 8.675.
```js
assert(getRating(watchList) === 8.675);
```
Your code should not use a `for` loop.
```js
assert(!code.match(/for\s*?\([\s\S]*?\)/g));
```
chore(learn): audit javascript algorithms and data structures (#41092) * chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-03 00:12:12 +00:00
Your code should return the correct output after modifying the `watchList` object.
```js
assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55);
```
# --seed--
## --seed-contents--
```js
// The global variable
var watchList = [
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
{
"Title": "Inception",
"Year": "2010",
"Rated": "PG-13",
"Released": "16 Jul 2010",
"Runtime": "148 min",
"Genre": "Action, Adventure, Crime",
"Director": "Christopher Nolan",
"Writer": "Christopher Nolan",
"Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy",
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
"Plot": "A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
"Language": "English, Japanese, French",
"Country": "USA, UK",
"Awards": "Won 4 Oscars. Another 143 wins & 198 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
"Metascore": "74",
"imdbRating": "8.8",
"imdbVotes": "1,446,708",
"imdbID": "tt1375666",
"Type": "movie",
"Response": "True"
},
{
"Title": "Interstellar",
"Year": "2014",
"Rated": "PG-13",
"Released": "07 Nov 2014",
"Runtime": "169 min",
"Genre": "Adventure, Drama, Sci-Fi",
"Director": "Christopher Nolan",
"Writer": "Jonathan Nolan, Christopher Nolan",
"Actors": "Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow",
"Plot": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.",
"Language": "English",
"Country": "USA, UK",
"Awards": "Won 1 Oscar. Another 39 wins & 132 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg",
"Metascore": "74",
"imdbRating": "8.6",
"imdbVotes": "910,366",
"imdbID": "tt0816692",
"Type": "movie",
"Response": "True"
},
{
"Title": "The Dark Knight",
"Year": "2008",
"Rated": "PG-13",
"Released": "18 Jul 2008",
"Runtime": "152 min",
"Genre": "Action, Adventure, Crime",
"Director": "Christopher Nolan",
"Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
"Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
"Plot": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
"Language": "English, Mandarin",
"Country": "USA, UK",
"Awards": "Won 2 Oscars. Another 146 wins & 142 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX300.jpg",
"Metascore": "82",
"imdbRating": "9.0",
"imdbVotes": "1,652,832",
"imdbID": "tt0468569",
"Type": "movie",
"Response": "True"
},
{
"Title": "Batman Begins",
"Year": "2005",
"Rated": "PG-13",
"Released": "15 Jun 2005",
"Runtime": "140 min",
"Genre": "Action, Adventure",
"Director": "Christopher Nolan",
"Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
"Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
"Plot": "After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.",
"Language": "English, Urdu, Mandarin",
"Country": "USA, UK",
"Awards": "Nominated for 1 Oscar. Another 15 wins & 66 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1_SX300.jpg",
"Metascore": "70",
"imdbRating": "8.3",
"imdbVotes": "972,584",
"imdbID": "tt0372784",
"Type": "movie",
"Response": "True"
},
{
"Title": "Avatar",
"Year": "2009",
"Rated": "PG-13",
"Released": "18 Dec 2009",
"Runtime": "162 min",
"Genre": "Action, Adventure, Fantasy",
"Director": "James Cameron",
"Writer": "James Cameron",
"Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
"Plot": "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
"Language": "English, Spanish",
"Country": "USA, UK",
"Awards": "Won 3 Oscars. Another 80 wins & 121 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg",
"Metascore": "83",
"imdbRating": "7.9",
"imdbVotes": "876,575",
"imdbID": "tt0499549",
"Type": "movie",
"Response": "True"
}
];
function getRating(watchList){
// Only change code below this line
var averageRating;
// Only change code above this line
return averageRating;
}
console.log(getRating(watchList));
```
# --solutions--
```js
// The global variable
var watchList = [
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
{
"Title": "Inception",
"Year": "2010",
"Rated": "PG-13",
"Released": "16 Jul 2010",
"Runtime": "148 min",
"Genre": "Action, Adventure, Crime",
"Director": "Christopher Nolan",
"Writer": "Christopher Nolan",
"Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy",
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
"Plot": "A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
"Language": "English, Japanese, French",
"Country": "USA, UK",
"Awards": "Won 4 Oscars. Another 143 wins & 198 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
"Metascore": "74",
"imdbRating": "8.8",
"imdbVotes": "1,446,708",
"imdbID": "tt1375666",
"Type": "movie",
"Response": "True"
},
{
"Title": "Interstellar",
"Year": "2014",
"Rated": "PG-13",
"Released": "07 Nov 2014",
"Runtime": "169 min",
"Genre": "Adventure, Drama, Sci-Fi",
"Director": "Christopher Nolan",
"Writer": "Jonathan Nolan, Christopher Nolan",
"Actors": "Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow",
"Plot": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.",
"Language": "English",
"Country": "USA, UK",
"Awards": "Won 1 Oscar. Another 39 wins & 132 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg",
"Metascore": "74",
"imdbRating": "8.6",
"imdbVotes": "910,366",
"imdbID": "tt0816692",
"Type": "movie",
"Response": "True"
},
{
"Title": "The Dark Knight",
"Year": "2008",
"Rated": "PG-13",
"Released": "18 Jul 2008",
"Runtime": "152 min",
"Genre": "Action, Adventure, Crime",
"Director": "Christopher Nolan",
"Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
"Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
"Plot": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
"Language": "English, Mandarin",
"Country": "USA, UK",
"Awards": "Won 2 Oscars. Another 146 wins & 142 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX300.jpg",
"Metascore": "82",
"imdbRating": "9.0",
"imdbVotes": "1,652,832",
"imdbID": "tt0468569",
"Type": "movie",
"Response": "True"
},
{
"Title": "Batman Begins",
"Year": "2005",
"Rated": "PG-13",
"Released": "15 Jun 2005",
"Runtime": "140 min",
"Genre": "Action, Adventure",
"Director": "Christopher Nolan",
"Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
"Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
"Plot": "After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.",
"Language": "English, Urdu, Mandarin",
"Country": "USA, UK",
"Awards": "Nominated for 1 Oscar. Another 15 wins & 66 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1_SX300.jpg",
"Metascore": "70",
"imdbRating": "8.3",
"imdbVotes": "972,584",
"imdbID": "tt0372784",
"Type": "movie",
"Response": "True"
},
{
"Title": "Avatar",
"Year": "2009",
"Rated": "PG-13",
"Released": "18 Dec 2009",
"Runtime": "162 min",
"Genre": "Action, Adventure, Fantasy",
"Director": "James Cameron",
"Writer": "James Cameron",
"Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
"Plot": "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
"Language": "English, Spanish",
"Country": "USA, UK",
"Awards": "Won 3 Oscars. Another 80 wins & 121 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg",
"Metascore": "83",
"imdbRating": "7.9",
"imdbVotes": "876,575",
"imdbID": "tt0499549",
"Type": "movie",
"Response": "True"
}
];
function getRating(watchList){
var averageRating;
const rating = watchList
fix(curriculum): Improve verbiage and add examples to the map, filter, and reduce challenges (#37709) * fix: improve verbiage and add examples to challenges * fix: condensed map method wording Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: remove leading space Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce challenge verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shorten verbiage related to reduce 2nd parameter Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened filter verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix; added comma Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: improved verbiage of map method Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: shortened reduce verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: correct map method verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added word array Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: added missing comma Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: changed u to sumOfAges Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: created one sentence out of many Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * fix: changed to on each iteration Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: fixed verbiage in filter and map challenges
2019-11-27 02:03:09 +00:00
.filter(obj => obj.Director === "Christopher Nolan")
.map(obj => Number(obj.imdbRating));
averageRating = rating.reduce((accum, curr) => accum + curr)/rating.length;
return averageRating;
}
```