First 10 Days of 30 Days of Javascript
Madalitso Nyemba
Posted on October 24, 2023
In 2015, my coding journey kicked off, and I plunged headfirst into the world of development, starting with C++. Two whole years were dedicated to mastering this language, setting the stage for my coding adventures. Then, in 2017, a new chapter unfolded as I ventured into the vibrant world of web development, and that's when JavaScript made its debut in my life.
Throughout the years, I've had the pleasure of crafting various professional projects that have touched the lives of many. From systems development to creating mobile apps and tinkering with chrome extensions, I've tried my hand at it all. However, as time went on, a desire to dive deeper into the fundamental concepts of programming started to take root.
One fine day, while navigating the digital landscape of LeetCode, I stumbled upon a 30-day JavaScript challenge, seemingly tailored for beginners. Now, while I'd certainly graduated from the beginner stage, I decided to take on this challenge for a couple of good reasons.
Firstly, I was in need of some consistency in my coding journey. You see, I've had my struggles with staying consistent, and this challenge seemed like the perfect remedy.
Secondly, I wanted to expand my knowledge beyond the boundaries of popular frameworks like Vue, React, Angular, and React Native and get back to the basics of JavaScript.
Lastly, I was eager to shift from the habit of merely copying code from tutorials on how to do something, without truly grasping the intricacies of what was required of me.
My journey turned out to be quite an adventure, and every day started with a LeetCode challenge. Whether it was a quick five-second puzzle or a more challenging 30-minute quest, I tackled it with enthusiasm.
So, here's a peek into the highlights, solutions, and insights gathered during the first ten days of this fun-filled JavaScript exploration.
On Day 3, the question was as below in the comments and the solution I gave:
//Write a function expect that helps developers test their code.It should take in any value val and return an object with the following two functions.
// toBe(val) accepts another value and returns true if the two values === each other. If they are not equal, it should throw an error "Not Equal".
// notToBe(val) accepts another value and returns true if the two values !== each other. If they are equal, it should throw an error "Equal"
var expect = function(val) {
return{
toBe: (v) => {
if(val === v){
return true
}else{
throw new Error("Not Equal")
}
},
notToBe: (v) => {
if(val !== v){
return true
}else{
throw new Error("Equal")
}
}
}
};
This was an interesting question where it had to return an object with two functions and show testing proficiency by throwing errors as well as gauge a devs understanding of Javascript’s equality operators (===) as they may behave unexpectedly if not used correctly.
On Day 7
// Given an integer array nums, a reducer function fn, and an initial
//value init, return a reduced array.
// A reduced array is created by applying the following operation:
//val = fn(init, nums[0]), val = fn(val, nums[1]), val = fn(val, nums[2]), ...
// until every element in the array has been processed. The final value of
// val is returned.
// If the length of the array is 0, it should return init.
// Please solve it without using the built-in Array.reduce method.
var reduce = function(nums, fn, init) {
let val
if(nums.length == 0){
return init;
}
for(let i = 0; i<nums.length;i++){
if(i==0){
val = fn(init, nums[i])
}else{
val = fn(val, nums[i])
}
}
return val
};
This was interesting as it made me further understand how reducers work in Javascript as I studied them after submission of the task.
On Day 10
// Given a function fn, return a new function that is identical to the original function except that it ensures fn is called at most once.
// The first time the returned function is called, it should return the same result as fn.
// Every subsequent time it is called, it should return undefined.
var once = function(fn) {
let another = fn
let i = 0
return function(...args){
if(i==0){
i = 1
return another(...args)
}else{
return undefined
}
}
};
I found this interesting as can be useful in scenarios where you want to restrict certain functions to execute only once, like initialization routines or one-time setup operations.
In summary, this has been my first 10 days towards 30 days of Javascript challenge. This is the start of a series that shall be documented in chunks of 10 days. See you after 10 days. Happy coding.
Posted on October 24, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.