Created
April 1, 2022 12:45
-
-
Save jx13xx/a560c4c39c9cdf174d3206cd55465d8c to your computer and use it in GitHub Desktop.
reduce, map, filter example javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scores = [50, 6, 100, 0, 10, 75, 8, 60, 90, 80, 0, 30, 110]; | |
//Any scores that are below 10 needs to be multiplied by 10 and the new value included. | |
const boostSingleScores = scores.map(function (val) { | |
return (val < 10) ? val *10 : val; | |
}) | |
//Remove any scores that are over 100. | |
const removeOverScores = boostSingleScores.filter(function (value) { | |
return value <= 100; | |
}) | |
//Remove any scores that are 0 or below. | |
const belowZero = removeOverScores.filter(function (value) { | |
return value > 0; | |
}) | |
//Sum the scores. | |
const total = belowZero.reduce(function (accumalor, nextValue){ | |
return accumalor + nextValue; | |
},0); | |
//Provide a count for the number of scores still remaining. | |
const scoreCount = belowZero.reduce(function (cnt, value){ | |
console.log(value); | |
return cnt + 1; | |
},0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment