Created
April 10, 2019 04:04
-
-
Save mhaidarhanif/3a71329c3c8f467d6003fe06e6d56993 to your computer and use it in GitHub Desktop.
Daily Steps Tracker
This file contains 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 myDailySteps = [ | |
{ | |
day: 1, | |
steps: 1900 | |
}, | |
{ | |
day: 2, | |
steps: 2200 | |
}, | |
{ | |
day: 3, | |
steps: 900 | |
}, | |
{ | |
day: 4, | |
steps: 1200 | |
}, | |
{ | |
day: 5, | |
steps: 2400, | |
favorite: true | |
} | |
] | |
// ----------------------------------------------------------------------------- | |
const showDailyStepsData = data => { | |
for (let index = 0; index < data.length; index++) { | |
const item = data[index] | |
if (item.favorite === true) { | |
console.log(`[Day ${item.day}] ${item.steps} steps ⭐`) | |
} else { | |
console.log(`[Day ${item.day}] ${item.steps} steps`) | |
} | |
} | |
} | |
// ----------------------------------------------------------------------------- | |
const filterMostActiveDays = (data, minimumSteps) => { | |
let newDailySteps = [] | |
for (let index = 0; index < data.length; index++) { | |
const item = data[index] | |
if (item.steps > minimumSteps) { | |
newDailySteps.push(item) | |
} | |
} | |
return newDailySteps | |
} | |
// ----------------------------------------------------------------------------- | |
const minimumStepsInput = prompt( | |
'What is your target of minimum steps per day?' | |
) | |
const filteredData = filterMostActiveDays(myDailySteps, minimumStepsInput) | |
// ----------------------------------------------------------------------------- | |
console.log('Show all data:') | |
showDailyStepsData(myDailySteps) | |
console.log('') | |
console.log('Show only filtered data:') | |
showDailyStepsData(filteredData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment