Ever wanted to check an array for hollowness?! Of course you did! Code along, with my latest step-by-step #Codewars code challenge in #TypeScript (and German)! https://lnkd.in/dkvCQufm Hajime! 🙏 #javascript #nextjs #ssg
Daniel Kaser’s Post
More Relevant Posts
-
Researching on the reduce method in javascript, I found this little nugget of knowledge written by Jp Camara on the impact of using the spread operator (a for loop in essence) on large datasets and the simple yet super-powerful solution he and his team found to solve performance issues. Choosing a mutating array method like push over non-mutating methods like slice and concat can drastically improve the algorithmic complexity to 0(1) which basically means that it takes the same amount of time to add 10000 elements to an array as it would to add 1. The only caveat? Avoid mutating your original data, unless you create it locally and is safe to mutate before being returned. PS. I just found out you can console.time() and console.timeEnd() to track the running time of your code 😯 . Just me? I leave the article here, for future reference https://lnkd.in/e28JCiMV #javascript #bigO #codeperformance
Making Tanstack Table 1000x faster with a 1 line change
jpcamara.com
To view or add a comment, sign in
-
----------> ~~ and Math.floor() in Javascript *) In JavaScript, the ~~ (double tilde) is a bitwise NOT operator. When applied to a number, it performs a bitwise NOT operation on the number, which is essentially the same as applying the floor operation, but it is faster. It is often used as a quick way to truncate the decimal part of a number and convert it to an integer. ex: let number = 5.67; let truncatedNumber = ~~number; console.log(truncatedNumber); // Output: 5 *) Math.floor() is a built-in JavaScript function that returns the largest integer less than or equal to a given number. It rounds down the number to the nearest integer. let number = 8.99; let floorNumber = Math.floor(number); console.log(floorNumber); // Output: 8
To view or add a comment, sign in
-
Have you guys heard of these array functions toSorted(), toReversed() and toSpliced()? These functions have been introduced in ES2023. These three functions are the immutable versions of the well-known javascript array functions sort(), reverse() and splice(). Let's assume an array const original = [5,3,1,2,7] sort() v toSort() ✅ const sorted = original.sort() // [1,2,3,5,7] console.log(original) // [1,2,3,5,7] ✅ const sorted = original.toSorted() // [1,2,3,5,7] console.log(original) // [5,3,1,2,7] The same goes for reverse() and toReversed(). splice() v toSpliced() ✅ const spliced = original.splice(1,2,7,10) // [ 3, 1 ] console.log(original) // [5,7,10,2,7] ✅ const spliced = original.toSpliced(1,2,7,10) // [5,7,10,2,7] console.log(original) // [5,3,1,2,7] Do you know any more such functions? Please mention those in the comments. PS: You can learn more about such functions from this article: https://lnkd.in/g8tJNmh7 #javascriptdeveloper #javascriptprogramming #javascript #frontenddevelopment #backend #arrays #immutable #mutable
7 little-known JavaScript array methods: with(), copyWithin(), + 5 more
medium.com
To view or add a comment, sign in
-
New to JavaScript in ES2023 are these super handy methods : Object.groupBy(myArrayOfObjects, myCallback), myArray.lastIndexOf("a"), and array methods that don't change the original array but work like their predecessors, myArray.toSpliced(1, 1), .toSorted(), and .toReversed() ! https://lnkd.in/eTw_dV_P
What's New in JavaScript in 2023 – Changes with Code Examples
freecodecamp.org
To view or add a comment, sign in
-
Today's Rheinwerk Computing Blog posts introduces you to the reducer hook in React. Read here: https://lnkd.in/eECdqeDy #RheinwerkComputing #JavaScript #React
What Is the Reducer Hook in React?
blog.rheinwerk-computing.com
To view or add a comment, sign in
-
FourSum Problem solved in JavaScript. Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, d < n a, b, c, and d are distinct. nums[a] + nums[b] + nums[c] + nums[d] == target You may return the answer in any order. Example 1: Input: nums = [1,0,-1,0,-2,2], target = 0 Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]] Example 2: Input: nums = [2,2,2,2,2], target = 8 Output: [[2,2,2,2]]
To view or add a comment, sign in
-
2370. Longest Ideal Subsequence Current Streak: 56 🔥 Date: 25 - 04 - 2024 Code in Javascript: var longestIdealString = function(s, k) { const memo = new Array(32).fill(0) let max = 1 for (let i = 0; i < s.length; i++){ const curr = s.charCodeAt(i) - 97 let start = curr - k let end = curr + k let currMax = 0 if (start < 0) start = 0 if (end > 31) end = 31 for (let j = start; j <= end; j++){ currMax = Math.max(currMax, memo[j]) } memo[curr] = currMax + 1 max = Math.max(max, memo[curr]) } return max }; Doubt 🤷♀️: I have tried to solve this question by Stack, but at the time of submission I have facing an error s = "pvjcci" k = 4 as per Leetcode, its correct answer is 2 but I have tried my side its answer is 1 Code : class Solution { public: int longestIdealString(string s, int k) { stack<char>st; for(char i : s) { if(st.empty()) st.push(i); else if(abs(st.top() - i) <= k) st.push(i); } return st.size(); } }; #Leetcode #Javascript #cpp 🎯
To view or add a comment, sign in
-
In JavaScript, arrays are data structures that help you store and manage collections of elements. And you'll often need to figure out an array's length - which you can do in a few ways. In this guide, Heritage teaches you two common methods.
JavaScript Array Length – How to Find the Length of an Array in JS
freecodecamp.org
To view or add a comment, sign in
-
Friday Quizzz! What is the difference between var, let, and const in JavaScript? Write the answer in the comments. A. var is function-scoped, let is block-scoped, const is block-scoped and for constants B. var is block-scoped, let is function-scoped and for constants, const is block-scoped and for constants C. let and const is for React and Angular projects D. var is function-scoped, let is block-scoped, const is function-scoped and for constants BTW, the answer of the last week is: The @Qualifier annotation is used to resolve the conflict when there are multiple beans of the same type. By specifying the qualifier name, Spring knows which specific bean to inject when multiple beans are candidates for autowiring. For more tips, follow me on: https://lnkd.in/en84AtRh Don't forget to like, share and comment!
To view or add a comment, sign in
-
To Generate OTP with AlphaNumberic in JavaScript :- function genAlphaNum() { let digits = '0123456789abcdefghijklmnopqrstuvwxyz'; let OTP = ' ' ; ( initially empty String) let len = digits.length // here length is 36 for(let i =0; i<6;i++) { OTP += digits[Math.floor(Math.random ( ) * len ) ]; } return OTP; } console.log("Your 6 digit OTP is : ") console.log( genAlphaNum( ) ); 😐
To view or add a comment, sign in