Front End Technology Articles

Page 373 of 652

Valid triangle edges - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 525 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

The Keys and values method in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 300 Views

JavaScript provides several methods to extract keys and values from objects and Maps. The most common approaches are Object.keys(), Object.values() for plain objects, and the keys(), values() methods for ES6 Maps. Getting Keys from Objects Use Object.keys() to extract all property names from an object as an array: const myObject = { key1: "value1", key2: "value2", key3: "value3" }; const keys = Object.keys(myObject); console.log(keys); [ 'key1', 'key2', 'key3' ] Getting Values from Objects Object.values() extracts all property ...

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

Loop through a Dictionary in Javascript

Monica Mona
Monica Mona
Updated on 15-Mar-2026 12K+ Views

In JavaScript, a dictionary (or object) stores key-value pairs. There are several ways to loop through these pairs depending on whether you're working with plain objects, ES6 Maps, or custom implementations. Method 1: Using for...in Loop (Plain Objects) The for...in loop is the traditional way to iterate through object properties: const dictionary = { key1: "value1", key2: "value2", key3: "value3" }; for (let key in dictionary) { console.log(`Key: ${key}, Value: ${dictionary[key]}`); } Key: key1, Value: value1 ...

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

The Dictionary Class in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 511 Views

JavaScript doesn't have a built-in Dictionary class, but we can create our own using objects or the Map class. Here's a complete implementation of a custom Dictionary class called MyMap. Complete Dictionary Implementation class MyMap { constructor() { this.container = {}; } display() { console.log(this.container); } hasKey(key) { return key in this.container; } ...

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

Creating a hash table using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 480 Views

A hash table (also called hash map) is a data structure that stores key-value pairs and provides fast lookup, insertion, and deletion operations. In JavaScript, we can implement a hash table using arrays and a hash function to map keys to array indices. Basic Hash Table Structure Let's create a hash table class with collision resolution using chaining. We'll use an array of arrays where each index can hold multiple key-value pairs in case of hash collisions. class HashTable { constructor() { this.container = ...

Read More

Add elements to a hash table using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 1K+ Views

When adding elements to a hash table, the most crucial part is collision resolution. We're going to use chaining for the same. There are other algorithms you can read about here: https://en.wikipedia.org/wiki/Hash_table#Collision_resolution Now let's look at the implementation. We'll be creating a hash function that'll work on integers only to keep this simple. But a more complex algorithm can be used to hash every object. Hash Table Implementation First, let's create a complete hash table class with the necessary components: class HashTable { constructor(size = 11) { ...

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 3721–3730 of 6,519 articles
« Prev 1 371 372 373 374 375 652 Next »
Advertisements