From 6ca18b77d7120cadc1d062146f17987b232fa875 Mon Sep 17 00:00:00 2001 From: Ariel Date: Sat, 7 Jun 2025 18:18:12 -0600 Subject: [PATCH 1/9] Create fromCharCode.md --- .../terms/fromCharCode/fromCharCode.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md diff --git a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md new file mode 100644 index 00000000000..79b402dde16 --- /dev/null +++ b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md @@ -0,0 +1,46 @@ +--- +Title: 'fromCharCode' +Description: 'Its a static method that returns a string created from the specified sequence of UTF-16 code units.' +Subjects: + - 'Web Development' +Tags: + - 'Strings' + - 'Characters' + - 'JavaScript' + - 'Methods' +CatalogContent: + - 'paths/front-end-engineer-career-path' +--- + +JavaScript has three static methods for working with String Objects, one of these is **fromCharCode**, which allows you to obtain a string from a sequence of UTF-16 code units. + +## Syntax + +```javascript +String.fromCharCode() +String.fromCharCode(num1) +String.fromCharCode(num1, num2) +String.fromCharCode(num1, num2, /* …, */ numN) +``` + +### Parameters +At least one number between 0 and 65535 (0xFFFF) **representing a UTF-16 code unit**. Numbers greater than 0xFFFF are truncated to the last 16 bits. + +## Example + +```javascript +const nombre = String.fromCharCode(76, 105, 97, 110, 121, 10084, 65039); +console.log(nombre); // "Liany❤️" + +``` + +## Codebyte Example + +```codebyte/js +# Example runnable code block. +const secret = String.fromCharCode( + 76, 111, 110, 103, 32, 108, 105, 118, 101, 32, 116, 104, 101, 32, 107, 105, 116, 116, 105, 101, 115 +); +console.log(secret); // "Long live the kitties" + +``` From 0347691cb0e5be6dd051df7d160516b7dddfdfaf Mon Sep 17 00:00:00 2001 From: Ariel Date: Sun, 8 Jun 2025 11:51:46 -0600 Subject: [PATCH 2/9] Update fromCharCode.md --- .../strings/terms/fromCharCode/fromCharCode.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md index 79b402dde16..f816b21422b 100644 --- a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md +++ b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md @@ -17,13 +17,14 @@ JavaScript has three static methods for working with String Objects, one of thes ## Syntax ```javascript -String.fromCharCode() -String.fromCharCode(num1) -String.fromCharCode(num1, num2) -String.fromCharCode(num1, num2, /* …, */ numN) +String.fromCharCode(); +String.fromCharCode(num1); +String.fromCharCode(num1, num2); +String.fromCharCode(num1, num2, /* …, */ numN); ``` ### Parameters + At least one number between 0 and 65535 (0xFFFF) **representing a UTF-16 code unit**. Numbers greater than 0xFFFF are truncated to the last 16 bits. ## Example @@ -31,7 +32,6 @@ At least one number between 0 and 65535 (0xFFFF) **representing a UTF-16 code un ```javascript const nombre = String.fromCharCode(76, 105, 97, 110, 121, 10084, 65039); console.log(nombre); // "Liany❤️" - ``` ## Codebyte Example From b4287f93aa645138b1b8dd18f6bf58e2234b89e5 Mon Sep 17 00:00:00 2001 From: Ariel-GonzAguer Date: Sat, 14 Jun 2025 14:40:29 -0600 Subject: [PATCH 3/9] Fix formatting and improve clarity in fromCharCode() documentation --- .../terms/fromCharCode/fromCharCode.md | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md index 8dc70ef5757..3b53495c2f3 100644 --- a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md +++ b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md @@ -1,39 +1,4 @@ --- -<<<<<<< HEAD -Title: 'fromCharCode' -Description: 'Its a static method that returns a string created from the specified sequence of UTF-16 code units.' -Subjects: - - 'Web Development' -Tags: - - 'Strings' - - 'Characters' - - 'JavaScript' - - 'Methods' -CatalogContent: - - 'paths/front-end-engineer-career-path' ---- - -JavaScript has three static methods for working with String Objects, one of these is **fromCharCode**, which allows you to obtain a string from a sequence of UTF-16 code units. - -## Syntax - -```javascript -String.fromCharCode(); -String.fromCharCode(num1); -String.fromCharCode(num1, num2); -String.fromCharCode(num1, num2, /* …, */ numN); -``` - -### Parameters - -At least one number between 0 and 65535 (0xFFFF) **representing a UTF-16 code unit**. Numbers greater than 0xFFFF are truncated to the last 16 bits. - -## Example - -```javascript -const nombre = String.fromCharCode(76, 105, 97, 110, 121, 10084, 65039); -console.log(nombre); // "Liany❤️" -======= Title: 'fromCharCode()' Description: 'Returns a string created from the specified sequence of UTF-16 code units.' Subjects: @@ -78,7 +43,6 @@ The output of this code is: ```shell Liany❤️ ->>>>>>> db5dfa532754ec3cd5e41c22c711f1d5769e4bd4 ``` ## Codebyte Example From ffc139feb9e102f33ac1980e5dd36b9bd34c5186 Mon Sep 17 00:00:00 2001 From: Ariel-GonzAguer Date: Sat, 14 Jun 2025 15:55:58 -0600 Subject: [PATCH 4/9] Add documentation for the reduceRight() array method --- .../arrays/terms/reduceRight/reduceRight.md | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md diff --git a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md new file mode 100644 index 00000000000..78af31345b7 --- /dev/null +++ b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md @@ -0,0 +1,112 @@ +--- +Title: 'reduceRight()' +Description: 'Array method that apply a callback function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.' +Subjects: + - 'Computer Science' + - 'Web Development' +Tags: + - 'Arrays' + - 'JavaScript' + - 'Methods' +CatalogContent: + - 'introduction-to-javascript' + - 'paths/front-end-engineer-career-path' +--- + +The **`reduceRight()`** method of Array is an iterative method that execute a function against an accumulator and each value of the array, **from right-to-left**, to reduce it to a single value. + +## Syntax + +```pseudo +reduceRight(callbackFn) +reduceRight(callbackFn, initialValue) +``` + +**Parameters:** + +- `callbackFn`: A function to apply to each element in the array. Its return value becomes the value of the accumulator parameter on the next invocation of callbackFn. In last invocation, the return value becomes the return value of **reduceRight()**. +- `initialValue` (Optional): A Value to use as accumulator in the first call of the `callbackFn`. If no initial value is supplied, the last element in the array will be used. + +**Return value:** + +The resulting value of the reduction. + +## **reduceRight()** vs _reduce()_ + +The difference between **`reduceRight()`** method and _reduce()_ method is the order in which the function is executed. The **reduceRight()** method is executed from **right to left**, and the _reduce()_ method is executed from _left to right_. + +```js +// difference between `reduceRight()` and `reduce()` +const l = ['0', '2', '4', '6', '🐈', '→']; +const reduceMethod = l.reduce((prev, cur) => prev + cur); +const reduceRightMethod = l.reduceRight((prev, cur) => prev + cur); + +console.log(`reduceMethod : ${reduceMethod}`); // "0246🐈→" +console.log(`reduceRightMethod : ${reduceRightMethod}`); // "→🐈6420" +``` + +## Examples + +The following code shows the **reduceRight()** without a initial value, and the order of execution of the callback. + +```js +const michiArray = [0, 1, 2, 3, 4]; +const reducedMichi = michiArray.reduceRight( + (accumulator, currentValue) => accumulator + currentValue +); + +console.log(reducedMichi); +``` + +| call # | accumulator | currentValue | index | Return value | +| ----------- | ----------- | ------------ | ----- | ------------ | +| First call | 4 | 3 | 3 | 7 | +| Second call | 7 | 2 | 2 | 9 | +| Third call | 9 | 1 | 1 | 10 | +| Fourth call | 10 | 0 | 0 | 10 | + +The output of this code is: + +```shell +10 +``` + +The following code shows the **reduceRight()** with an initial value, and the order of execution of the callback. + +```js +const favoriteName = ['👑', 'y', 'n', 'a', 'i']; +const princess = favoriteName.reduceRight( + (accumulator, currentValue) => accumulator + currentValue, + 'L' +); + +console.log(princess); +``` + +| call # | accumulator | currentValue | index | Return value | +| ----------- | ----------- | ------------ | ----- | ------------ | +| First call | L | i | 4 | Li | +| Second call | Li | a | 3 | Lia | +| Third call | Lia | n | 2 | Lian | +| Fourth call | Lian | y | 1 | Liany | +| Fifth call | Liany | 👑 | 0 | Liany👑 | + +The output of this code is: + +```shell +Liany👑 +``` + +## Codebyte Example + +Run the following code to understand the working of the `fromCharCode()` method: + +```codebyte/javascript +const codingMessage = ["practice", " ", "of", " ", "lot", " ", "a", " ", "require", ", ", "code", " ", "to", " "]; + +const fullMessage = codingMessage.reduceRight( + (accumulator, currentValue) => accumulator + currentValue, "learning" +); + +console.log(fullMessage); +``` From e9b258fa20aa0ddcd6d7a1920983cdaabd33d618 Mon Sep 17 00:00:00 2001 From: Ariel-GonzAguer Date: Sat, 14 Jun 2025 16:05:19 -0600 Subject: [PATCH 5/9] Remove conflicting code block from Codebyte example in fromCharCode() documentation --- .../strings/terms/fromCharCode/fromCharCode.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md index 3b53495c2f3..4db46717c6e 100644 --- a/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md +++ b/content/javascript/concepts/strings/terms/fromCharCode/fromCharCode.md @@ -47,15 +47,6 @@ Liany❤️ ## Codebyte Example -<<<<<<< HEAD -```codebyte/js -# Example runnable code block. -const secret = String.fromCharCode( - 76, 111, 110, 103, 32, 108, 105, 118, 101, 32, 116, 104, 101, 32, 107, 105, 116, 116, 105, 101, 115 -); -console.log(secret); // "Long live the kitties" - -======= Run the following code to understand the working of the `fromCharCode()` method: ```codebyte/javascript @@ -63,5 +54,4 @@ const secret = String.fromCharCode( 76, 111, 110, 103, 32, 108, 105, 118, 101, 32, 116, 104, 101, 32, 107, 105, 116, 116, 105, 101, 115 ); console.log(secret); ->>>>>>> db5dfa532754ec3cd5e41c22c711f1d5769e4bd4 ``` From 80591080c9d847b3f715499fed6687c3782062dd Mon Sep 17 00:00:00 2001 From: Ariel-GonzAguer Date: Sat, 14 Jun 2025 16:12:06 -0600 Subject: [PATCH 6/9] Fix description formatting and update variable names in reduceRight() documentation --- .../concepts/arrays/terms/reduceRight/reduceRight.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md index 78af31345b7..fb439f0920e 100644 --- a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md +++ b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md @@ -1,6 +1,6 @@ --- Title: 'reduceRight()' -Description: 'Array method that apply a callback function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.' +Description: 'Array method that apply a callback function against an accumulator and each value of the array, from right-to-left to reduce it to a single value.' Subjects: - 'Computer Science' - 'Web Development' @@ -37,9 +37,10 @@ The difference between **`reduceRight()`** method and _reduce()_ method is the o ```js // difference between `reduceRight()` and `reduce()` -const l = ['0', '2', '4', '6', '🐈', '→']; -const reduceMethod = l.reduce((prev, cur) => prev + cur); -const reduceRightMethod = l.reduceRight((prev, cur) => prev + cur); +const stringArray = ['0', '2', '4', '6', '🐈', '→']; + +const reduceMethod = stringArray.reduce((prev, cur) => prev + cur); +const reduceRightMethod = stringArray.reduceRight((prev, cur) => prev + cur); console.log(`reduceMethod : ${reduceMethod}`); // "0246🐈→" console.log(`reduceRightMethod : ${reduceRightMethod}`); // "→🐈6420" From e262950fcf1b21e7dba58ccf0bc26c36a8cbc5cd Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 16 Jun 2025 19:10:28 +0530 Subject: [PATCH 7/9] content tweaks and structure --- .../arrays/terms/reduceRight/reduceRight.md | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md index fb439f0920e..41ce3cb9e8f 100644 --- a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md +++ b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md @@ -1,6 +1,6 @@ --- Title: 'reduceRight()' -Description: 'Array method that apply a callback function against an accumulator and each value of the array, from right-to-left to reduce it to a single value.' +Description: 'Applies a reducer function to array elements from right to left, accumulating a single output value.' Subjects: - 'Computer Science' - 'Web Development' @@ -13,42 +13,54 @@ CatalogContent: - 'paths/front-end-engineer-career-path' --- -The **`reduceRight()`** method of Array is an iterative method that execute a function against an accumulator and each value of the array, **from right-to-left**, to reduce it to a single value. +The **`reduceRight()`** method in JavaScript executes a reducer function on each element of an array, from right to left, to produce a single accumulated result. It is commonly used when the order of operations matters—such as evaluating expressions, parsing nested structures, or performing right-associative computations like exponentiation. ## Syntax ```pseudo -reduceRight(callbackFn) reduceRight(callbackFn, initialValue) ``` **Parameters:** -- `callbackFn`: A function to apply to each element in the array. Its return value becomes the value of the accumulator parameter on the next invocation of callbackFn. In last invocation, the return value becomes the return value of **reduceRight()**. -- `initialValue` (Optional): A Value to use as accumulator in the first call of the `callbackFn`. If no initial value is supplied, the last element in the array will be used. +- `callbackFn`: A function to execute on each element in the array. It takes four arguments: + - `accumulator`: The accumulated result from the previous callback. + - `currentValue`: The current element being processed. + - `currentIndex`: The index of the current element. + - `array`: The array `reduceRight()` was called upon. +- `initialValue` (Optional): A value to use as the first argument to the first call of `callbackFn`. If not provided, the last element in the array is used as the initial value, and iteration starts from the second-to-last element. **Return value:** -The resulting value of the reduction. +Returns a single value resulting from the reduction of the array, working from right to left. -## **reduceRight()** vs _reduce()_ +## `reduceRight()` vs `reduce()` -The difference between **`reduceRight()`** method and _reduce()_ method is the order in which the function is executed. The **reduceRight()** method is executed from **right to left**, and the _reduce()_ method is executed from _left to right_. +- `reduce()` processes array elements from left to right, useful for left-associative operations like summing or accumulating values. +- `reduceRight()` processes elements from right to left, ideal for right-associative logic like parsing or reversing operations. + +In the following example, `reduce()` combines array elements from left to right, while `reduceRight()` combines them from right to left, resulting in reversed concatenation: ```js -// difference between `reduceRight()` and `reduce()` const stringArray = ['0', '2', '4', '6', '🐈', '→']; const reduceMethod = stringArray.reduce((prev, cur) => prev + cur); const reduceRightMethod = stringArray.reduceRight((prev, cur) => prev + cur); -console.log(`reduceMethod : ${reduceMethod}`); // "0246🐈→" -console.log(`reduceRightMethod : ${reduceRightMethod}`); // "→🐈6420" +console.log(`reduceMethod : ${reduceMethod}`); +console.log(`reduceRightMethod : ${reduceRightMethod}`); +``` + +It generates the following output: + +```shell +reduceMethod : 0246🐈→ +reduceRightMethod : →🐈6420 ``` -## Examples +## Example 1: Reverse Sum with `reduceRight()` -The following code shows the **reduceRight()** without a initial value, and the order of execution of the callback. +The following code shows the `reduceRight()` without an initial value, and the order of execution of the callback: ```js const michiArray = [0, 1, 2, 3, 4]; @@ -72,7 +84,9 @@ The output of this code is: 10 ``` -The following code shows the **reduceRight()** with an initial value, and the order of execution of the callback. +## Example 2: Reverse Name Construction with `reduceRight()` + +The following code shows the `reduceRight()` with an initial value, and the order of execution of the callback: ```js const favoriteName = ['👑', 'y', 'n', 'a', 'i']; @@ -90,7 +104,7 @@ console.log(princess); | Second call | Li | a | 3 | Lia | | Third call | Lia | n | 2 | Lian | | Fourth call | Lian | y | 1 | Liany | -| Fifth call | Liany | 👑 | 0 | Liany👑 | +| Fifth call | Liany | 👑 | 0 | Liany👑 | The output of this code is: @@ -100,7 +114,7 @@ Liany👑 ## Codebyte Example -Run the following code to understand the working of the `fromCharCode()` method: +Run the following code to understand the working of the `reduceRight()` method: ```codebyte/javascript const codingMessage = ["practice", " ", "of", " ", "lot", " ", "a", " ", "require", ", ", "code", " ", "to", " "]; From 6b23da13e0c2ef315398b89a8ed4ae9456650eac Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 16 Jun 2025 19:11:09 +0530 Subject: [PATCH 8/9] Update reduceRight.md --- .../javascript/concepts/arrays/terms/reduceRight/reduceRight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md index 41ce3cb9e8f..35b30f6cce1 100644 --- a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md +++ b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md @@ -36,7 +36,7 @@ Returns a single value resulting from the reduction of the array, working from r ## `reduceRight()` vs `reduce()` -- `reduce()` processes array elements from left to right, useful for left-associative operations like summing or accumulating values. +- [`reduce()`](https://www.codecademy.com/resources/docs/javascript/arrays/reduce) processes array elements from left to right, useful for left-associative operations like summing or accumulating values. - `reduceRight()` processes elements from right to left, ideal for right-associative logic like parsing or reversing operations. In the following example, `reduce()` combines array elements from left to right, while `reduceRight()` combines them from right to left, resulting in reversed concatenation: From f03b29695910151438386ac7422a6f45dc679cb2 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 16 Jun 2025 19:50:15 +0530 Subject: [PATCH 9/9] Update reduceRight.md --- .../javascript/concepts/arrays/terms/reduceRight/reduceRight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md index 35b30f6cce1..c074d83afc8 100644 --- a/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md +++ b/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md @@ -104,7 +104,7 @@ console.log(princess); | Second call | Li | a | 3 | Lia | | Third call | Lia | n | 2 | Lian | | Fourth call | Lian | y | 1 | Liany | -| Fifth call | Liany | 👑 | 0 | Liany👑 | +| Fifth call | Liany | 👑 | 0 | Liany👑 | The output of this code is: