Mapping out the ranking! (JavaScript)

.map()
let newArray = arr.map(callback(currentValue[, index[, array]]) {
// return element for newArray, after executing something
}[, thisArg]);
.filter()
let newArray = arr.filter(callback(currentValue[, index[, array]]) {
// return element for newArray, if true
}[, thisArg]);
.reduce()
arr.reduce(callback( accumulator, currentValue, [, index[, array]] )[, initialValue])
let racers = []
let position = 1
function addRacerToRacers(racer){
let racer = {name: racer, position: position)
position++
racers.push(racer)
}
function displayRacers(racers){
for(let i =0; i<racers.length; i++){
let name = racers[i].name
let position = racers[i].position
createRacerCard(name,position)
}
return "Race Completed"
}
let racers = []
function addRacerToRacers(racer){
racers.push(racer)
}
function displayRacers(racers){
racers.map((racer, index) => createRacerCard(racer, index +1))
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store