Forwarded from Poll Creator
Try to guess the answer before seeing the answer.
The output will be "122" because JavaScript treats the first "1" as a string, causing concatenation instead of addition.
I have started “30 days of JavaScript“ study plan in Leetcode. Solved four problems and finished first section. First and second problems were quite easy. I will share my solution for remaining two problems.
Let’s make 10 day challenge to solve at least one problem a day. You also can start the challenge! Let’s rock this challenge!t
Let’s make 10 day challenge to solve at least one problem a day. You also can start the challenge! Let’s rock this challenge!t
2665. Counter II
Fourth photo: Another solution I liked in Solutions section.
Fourth photo: Another solution I liked in Solutions section.
Programming notes
I have started “30 days of JavaScript“ study plan in Leetcode. Solved four problems and finished first section. First and second problems were quite easy. I will share my solution for remaining two problems. Let’s make 10 day challenge to solve at least…
LeetCode
30 Days of JavaScript - Study Plan - LeetCode
Learn JS Basics with 30 Qs
💾 Memory: 48.79 MB. Beats 59.75%
▶️ Pre-allocate Memory: By creating a new array with new Array(arr.length), we allocate the required memory upfront, which can be more efficient for large arrays.
const newArray = new Array(arr.length);
▶️ Direct Assignment: Assigning the transformed value directly to the array index avoids the overhead of the push operation.
newArray[i] = fn(arr[i], i);
Will wait for reactions
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
💾 Memory: 48.67 MB. Beats 81.42%
🔗 Link: https://leetcode.com/problems/filter-elements-from-array/description/?envType=study-plan-v2&envId=30-days-of-javascript
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Precompute length
Storing nums.length in a variable avoids recomputing the length of the array on every iteration.
This reduced runtime from 53 ms to 42 ms.
@leetcode_javascript
Storing nums.length in a variable avoids recomputing the length of the array on every iteration.
This reduced runtime from 53 ms to 42 ms.
@leetcode_javascript
The reduceRight() method executes a reducer function for each array element.
The reduceRight() method works from right to left.
The reduceRight() method returns a single value: the function's accumulated result.
The reduceRight() method does not execute the function for empty elements.
💪 10 Day Challenge: Day 4 ✅
@leetcode_javascript
The reduceRight() method works from right to left.
The reduceRight() method returns a single value: the function's accumulated result.
The reduceRight() method does not execute the function for empty elements.
@leetcode_javascript
Please open Telegram to view this post
VIEW IN TELEGRAM