Day 4 of 100 Days Of Code
Day 4: July 28, Saturday
Today’s Progress: I’ve gone through the next few exercises on FreeCodeCamp Basic Data Structures.
Thoughts I knew this was going to be tricky, I remembered over thinking a couple of the challenges yesterday but even though I tried to keep it simple, but once again I made at least one spaghetti code monster :monster: I had a hard time with one of the challenges, I usually rely on JS Libraries Writing your own JS can be challenging.
//Copy Array Items Using slice()
function forecast(arr) {
// change code below this line
return arr.slice(2, 4); //My solution
}
// do not change code below this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
Another way of doing it (This was the first way I tried it)\
I had to add debugging statements to find where i was missing the unit test.
function forecastAlt(arr) {
// change code below this line
let myArr = arr.slice(2, 4) ;
console.log("This is the content of myArr = " + myArr); //for debugging
console.log("This is the content of arr = " + arr); //for debugging
return arr = myArr; //my solution
//(after hours fighting code, once I put the debug statements in it was pretty clear)
}
// do not change code below this line
console.log(forecastAlt(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
Link(s) to work
- PassedAdd Items Using splice()
- PassedCopy Array Items Using slice()
- PassedCopy an Array with the Spread Operator
- PassedCombine Arrays with the Spread Operator
- PassedCheck For The Presence of an Element With indexOf()
- PassedIterate Through All an Array’s Items Using For Loops
- PassedCreate complex multi-dimensional arrays
Written on July 28, 2018