This folder contains solutions to easy-level problems encountered on LeetCode. Each problem is explained with a link to the LeetCode problem and the corresponding solution file.
- Create Hello World Function
- Counter
- To Be Or Not To Be
- Counter II
- Apply Transform Over Each Element in Array
- Filter Elements from Array
- Description: Write a function called
createHelloWorld. This function should return a new function that, when called, always returns the stringHello World. - LeetCode Link: create-hello-world-function
- Solution File: create-hello-world-function.js
- Description: Given an integer
n, write a function calledcreateCounter. This function should return another function that initially returnsn, and each subsequent call to this counter function should return one more than the previous value (i.e.,n,n + 1,n + 2, etc.). - LeetCode Link: counter
- Solution File: counter.js
- Description: Write a function
expectthat helps developers test their code. It should take in any valuevaland return an object with the following two functions:toBe(val): Accepts another value and returnstrueif the two values are strictly equal (===). If they are not equal, it should throw an error"Not Equal".notToBe(val): Accepts another value and returnstrueif the two values are not equal (!==). If they are equal, it should throw an error"Equal".
- LeetCode Link: to-be-or-not-to-be
- Solution File: to-be-or-not-to-be.js
- Description: Write a function
createCounter. It should accept an initial integer and return an object with the following three functions:increment(): Increases the current value by 1 and returns it.decrement(): Decreases the current value by 1 and returns it.reset(): Sets the current value toinitand then returns it.
- LeetCode Link: counter-ii
- Solution File: counter-2.js
- Description: Given an array
arrand a mapping functionfn, return a new array with a transformation applied to each element. The returned array should be created such thatreturnedArray[i] = fn(arr[i], i). - LeetCode Link: apply-transform-over-each-element-in-array
- Solution File: transform-array.js
- Description: Given an integer array
arrand a filtering functionfn, return a filtered arrayfilteredArrthat contains only the elements for which the expressionfn(arr[i], i)evaluates to a truthy value. - LeetCode Link: filter-elements-from-array
- Solution File: filter-array.js