Web Development Articles

Page 469 of 801

Valid triangle edges - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 524 Views

In geometry, three lines can form a triangle only if they satisfy the triangle inequality theorem: the sum of any two sides must be greater than the third side. This fundamental rule ensures that the three sides can actually connect to form a closed triangle. For example, if three lines have lengths 4, 9, and 3, they cannot form a triangle because 4 + 3 = 7, which is less than 9. At least one side would be too long to connect with the other two. Triangle Inequality Theorem For sides with lengths a, b, and c ...

Read More

How to do Butterfly Shuffle in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 450 Views

A butterfly shuffled array in JavaScript is an array of Numbers that is sorted such that the numbers decrease as we approach the center of array and increase as we approach the end of array. The biggest number is placed at the very first index. Another variation of butterfly shuffled array is where the numbers increase towards the center and decrease towards the end. In this case the smallest number is placed at the very first index. For people who come from a Mathematics background, it's somewhat relatable to the Gaussian distribution. Example Suppose we have ...

Read More

How to count a depth level of nested JavaScript objects?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

We have an array of objects, which further have nested objects like this − const arr = [{ id: 0, children: [] }, { id: 1, children: [{ id: 2, children: [] }, { id: 3, children: [{ id: 4, children: [] }] }] }]; ...

Read More

Absolute sum of array elements - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 882 Views

We are required to write a JavaScript function that takes in an array with both positive and negative numbers and returns the absolute sum of all the elements of the array. We are required to do this without taking help of any inbuilt library function. For example: If the array is − const arr = [1, -5, -34, -5, 2, 5, 6]; Then the output should be − 58 Understanding Absolute Sum The absolute sum means we convert all negative numbers to positive and then add all elements. For ...

Read More

In JavaScript, need to perform sum of dynamic array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 393 Views

Let's say, we have an array that contains the score of some players in different sports. The scores are represented like this − const scores = [ {sport: 'cricket', aman: 54, vishal: 65, jay: 43, hardik: 88, karan:23}, {sport: 'soccer', aman: 14, vishal: 75, jay: 41, hardik: 13, karan:73}, {sport: 'hockey', aman: 43, vishal: 35, jay: 53, hardik: 43, karan:29}, {sport: 'volleyball', aman: 76, vishal: 22, jay: 36, hardik: 24, karan:47}, {sport: 'baseball', aman: 87, vishal: 57, jay: 48, hardik: 69, karan:37}, ]; We need to ...

Read More

Change every letter to next letter - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 799 Views

We are required to write a JavaScript function that takes in a string and changes every letter of the string from the English alphabets to its succeeding element. For example: If the string is − const str = 'how are you'; Then the output should be − const output = 'ipx bsf zpv'; How It Works The algorithm processes each character by checking if it's a letter using ASCII codes. For letters 'a-y' and 'A-Y', it moves to the next letter. For 'z' and 'Z', it wraps around to 'a' and 'A' respectively. Non-alphabetic ...

Read More

Filter the properties of an object based on an array and get the filtered object JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 506 Views

In JavaScript, you often need to filter an object's properties based on specific criteria. This article shows how to create a filtered object containing only the properties whose keys appear in a given array. Problem Statement We need to write a function that takes an object and an array of string literals, then returns a new object containing only the key-value pairs where the key exists in the array. For example: If the object is {"a": [], "b": [], "c": [], "d": []} and the array is ["a", "d"], the output should be: {"a": [], ...

Read More

Repeating letter string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We are required to write a JavaScript function that takes in a string and a number, say n, and the function should return a new string in which all the letters of the original string are repeated n times. For example: If the string is − const str = 'how are you' And the number n is 2 Then the output should be − const output = 'hhooww aarree yyoouu' Example Following is the code − const str = 'how are you'; const repeatNTimes ...

Read More

map() array of object titles into a new array based on other property value JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 287 Views

Let's say, we have an array of objects like this − const arr = [{ country: "canada", count: 2 }, { country: "jamaica", count: 2 }, { country: "russia", count: 1 }, { country: "india", count: 3 }, { country: "spain", count: 2 }, { country: "portugal", count: 1 }, ...

Read More

Finding missing letter in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 760 Views

We have a string of length m that contains first m letters of the English alphabets, but somehow, one element went missing from the string. So, now the string contains, m-1 letters We are required to write a function that takes in one such string and returns the missing element from the string. Example Following is the code − const str = "acdghfbekj"; const missingCharacter = str => { // to make the function more consistent const s = str.toLowerCase(); ...

Read More
Showing 4681–4690 of 8,010 articles
« Prev 1 467 468 469 470 471 801 Next »
Advertisements