Programming notes
256 subscribers
438 photos
1 video
1 file
130 links
Student at the University of Arkansas 🇺🇸

In Uzbek @uzbekode
Download Telegram
Forwarded from Poll Creator
What is the output to the console?
Anonymous Quiz
20%
5
38%
122
41%
14
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've got some news 😀
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
2704. To Be Or Not To Be
2665. Counter II

Fourth photo: Another
solution I liked in Solutions section.
🖥 Problem: 2635. Apply Transform Over Each Element in Array

⚡️ Runtime: 55 ms. Beats 37.56%

💾 Memory: 48.79 MB. Beats 59.75%

💪 10 Day Challenge: Day 2

🤔 Optimization:

▶️ 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
🖥 Problem: 2634. Filter Elements from Array

⚡️ Runtime: 48 ms. Beats 83.58%

💾 Memory: 48.67 MB. Beats 81.42%

💪 10 Day Challenge: Day 3

🔗 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
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
Please open Telegram to view this post
VIEW IN TELEGRAM