Day 42: A Breakthrough While Using the reduce Method
#100DaysOfCode Challenge

Search for a command to run...
#100DaysOfCode Challenge

No comments yet. Be the first to comment.
How Perseverance Led Me to Data Analytics

An SQL cheat sheet for beginners

My top learning resources and why I like them

A how-to- guide with code snippets and a live demo

My Top 7 Git Commands and How I Use Them

I had a breakthrough while writing a function using the reduce method and I'm 75% done with 'Functional Programming' section of freeCodeCamp's JavaScript Algoothms and Data Structure course.
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." reduce is calledreduce also 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."reduce to calculate a sumsort method sorts elements of an array in ascending order (by default) BUT this based on converting the elements into strings and comparing the Unicode point value. However, this can return unexpected results. Thus, it's best practice to provide a callback function (usually called compareFunction) to define how you want the elements sorted. More details here.sort method mutates the array it's called upon. One way to avoid this is to first concatenate an empty array to the one being sorted, then run the sort methodI had a breakthrough in today's session: I managed to write an entire function without having to consult a "bazzillion" different sources. Lately I've had to refer to several different resources (e.g., documentation, forum posts, videos) to get through challenges. But today was different and it felt great!
While working on the challenge, I read the instructions carefully, broke the task into pieces, and only needed to refer to the MDN documentation once - and that was just for clarification on how syntax works for the reduce method. That's it!
It might not sound like a lot, but I almost screamed, "F*ck yeah!" when I saw the 'Tests passed' pop-up, but restrained myself since I was studying late and didn't want to disturb my partner (who was sleeping in the other room).
Feeling good about today's session and looking forward to more studying this weekend. (-:
The following documentation was useful into today's challenges:
https://www.freecodecamp.org/ananfito
You can read my full #100DaysOfCode journal on GitHub