Skip to content

Commit d03936a

Browse files
committed
adding description
1 parent b921fe4 commit d03936a

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

easy/array-reduce-transformation.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* Reduces an array of numbers to a single value using a provided function and initial value.
3+
*
4+
* @param {number[]} numbers - The array of numbers to reduce.
5+
* @param {function} fn - The function to apply to each element and the accumulator. It takes two arguments: the accumulator and the current element.
6+
* @param {number} init - The initial value of the accumulator.
7+
* @returns {number} - The final reduced value after applying the function to all elements.
8+
*/
9+
110
const reduce = (numbers, fn, init) => {
211
numbers.forEach((element) => {
312
init = fn(init, element);

easy/filter-array.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* Filters an array based on a provided function and returns a new array with elements that pass the test.
3+
*
4+
* @param {Array} arr - The array of elements to be filtered.
5+
* @param {function} fn - The function to test each element. It takes two arguments: the current element and its index. Should return a boolean indicating whether the element should be included in the new array.
6+
* @returns {Array} - A new array containing only the elements that passed the test.
7+
*/
8+
19
const filter = (arr, fn) => {
210
let filteredArr = [];
311
arr.forEach((element, index) => {

easy/to-be-or-not-to-be.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* Creates an object with methods for testing value equality.
3+
*
4+
* @param {*} val - The value to be tested.
5+
* @returns {object} - An object with two methods:
6+
* - `toBe(expected)`: Checks if `val` is strictly equal to `expected`. Throws an error if they are not equal.
7+
* - `notToBe(expected)`: Checks if `val` is not strictly equal to `expected`. Throws an error if they are equal.
8+
*/
9+
110
const expect = (val) => {
211
return {
312
toBe: (expected) => {

easy/transform-array.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* Applies a transformation function to each element in an array and returns a new array with the transformed elements.
3+
*
4+
* @param {Array} arr - The array of elements to be transformed.
5+
* @param {function} fn - The function to apply to each element in the array. It takes two arguments: the current element and its index.
6+
* @returns {Array} - A new array containing the results of applying `fn` to each element in `arr`.
7+
*/
8+
19
const map = (arr, fn) => {
210
let transformedArray = [];
311
arr.forEach((item, index) => {

0 commit comments

Comments
 (0)