So I spend some 10 hours doing the Exercise Tracker project. About 7 hours were spent just testing to see if things would work and debugging.
Tbh if I had read some requirements with more care it would have taken at least 2 hours less debugging time.
Now at the end when I tested everything on postman and my localhost I decided to give it a go on fcc and I was failing ~50% of the test.
Moral of the story: check your routes from time to time.
Somehow I managed to get it working and by that, I mean that I just used the right path. The code is awful, might post it after some refactoring. There were a lot of things to learn. Thanks, fCC!
Also:
Just noticed that filter's return doesn’t change the array you call it on but map might with the callback. Still investigating. In that specific situation using a for loop didn’t seem to be an option.
Here I’m talking about the date element. Changing map with filter will give 2 different results as filter won’t apply the new Date(element.date).toDateString()
At this point, answer is an object and has the same structure that I’m rebuilding. I’m just changing its date type from date to string.
Was it supposed to be like a small reward for completing the others? As long as I’m not missing something it’s way easier than the 2 projects before it. You don’t even have to write files or use a db. Quite strange. I thought that the projects were placed in increasing difficulty.
Yea my bad. I’m still learning to formulate my ideas clearly. For me this difference between filter and map was strange:
module.exports.mapMutation = function mapMutation() {
var answer = {
log: [{ date: "2022-02-03T22:35:26.886+00:00" }, { date: "1998-02-03T22:35:26.886+00:00" }],
};
// console.log("original:", answer.log);
// original: [ { date: '1' }, { date: '2' } ]
var answer2 = {
log: answer.log.map((element) => {
return {
date: new Date(element.date).toDateString(),
};
}),
};
var answer3 = {
log: answer.log.filter((element) => {
return {
date: new Date(element.date).toDateString(),
};
}),
};
console.log("original:", answer.log);
// original: [
// { date: '2022-02-03T22:35:26.886+00:00' },
// { date: '1998-02-03T22:35:26.886+00:00' }
// ]
console.log("new with map:", answer2.log);
// new with map: [ { date: 'Fri Feb 04 2022' }, { date: 'Wed Feb 04 1998' } ]
console.log("new with filter:", answer3.log);
// new with filter: [
// { date: '2022-02-03T22:35:26.886+00:00' },
// { date: '1998-02-03T22:35:26.886+00:00' }
}
I meant to say that by using map I could attribute to let’s say answer2 a modified value from answer. With filter I expected it to work the same but that wasn’t the case.