Front End Technology Articles

Page 372 of 652

Remove elements from a Set using Javascript

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

JavaScript Sets provide methods to remove elements efficiently. The primary method is delete(), which removes a specified value from the Set. Using the delete() Method The delete() method removes a value from the Set and returns true if the value existed, or false if it didn't. Syntax set.delete(value) Example: Removing Individual Elements const mySet = new Set([1, 2, 3, 4, 5]); console.log("Original Set:", mySet); // Remove elements console.log("Delete 3:", mySet.delete(3)); // true - existed console.log("Delete 10:", mySet.delete(10)); // false - didn't exist console.log("Updated Set:", mySet); console.log("Set size:", ...

Read More

Checking Oddish and Evenish numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 309 Views

A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even. We need to write a function that determines whether a number is Oddish or Evenish. The function should return true for Oddish values and false for Evenish values. How It Works The algorithm extracts each digit from the number, adds them up, and checks if the sum is odd or even: Extract digits using modulo (num % 10) and integer division (Math.floor(num / 10)) Sum all ...

Read More

The Set Class in Javascript

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

JavaScript's built-in Set class is a collection of unique values that allows you to store distinct elements of any type. Unlike arrays, Sets automatically prevent duplicate values and provide efficient methods for adding, removing, and checking element existence. Creating a Set You can create a Set using the new Set() constructor, optionally passing an iterable like an array: // Empty set let mySet = new Set(); // Set from array let numbersSet = new Set([1, 2, 3, 4, 4, 5]); console.log(numbersSet); // Duplicates are automatically removed let wordsSet = new Set(['hello', 'world', 'hello']); console.log(wordsSet); ...

Read More

Neutralisation of strings - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 285 Views

In JavaScript, string neutralisation involves evaluating a string containing only '+' and '-' characters to determine the overall sign. The concept is based on mathematical sign multiplication: like signs produce '+', unlike signs produce '-'. How Neutralisation Works The neutralisation follows these rules: ++ results in + (positive × positive = positive) -- results in + (negative × negative = positive) +- or -+ results in - (positive × negative = negative) Example String Let's work with the following string: const str = '+++-+-++---+-+--+-'; Implementation Here's how to implement ...

Read More

Dictionary Data Structure in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection. Note that a dictionary is also known as a map. The dictionary problem is a classic computer science problem: the task of designing a data structure that maintains a set of data during 'search', 'delete', and 'insert' operations. There are many different types of implementations of dictionaries. Hash Table implementation Tree-Based Implementation (Self-balancing ...

Read More

Creating Dictionary using Javascript

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

In JavaScript, dictionaries can be created using objects, the ES6 Map class, or custom implementations. Each approach offers different features and use cases. Using Objects as Dictionaries The simplest way to create a dictionary is using plain JavaScript objects: // Creating a dictionary using object literal const dict = { "key1": "value1", "key2": "value2", "key3": "value3" }; console.log(dict["key1"]); console.log(dict.key2); value1 value2 Using ES6 Map Class The Map class provides a more robust dictionary implementation with additional methods: ...

Read More

Reverse only the odd length words - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 584 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an odd number of characters in them. Any substring in the string qualifies to be a word, if either it is encapsulated by two spaces on either ends or present at the end or beginning and followed or preceded by a space. Let's say the following is our string: const str = 'hello beautiful people'; The odd length words are: hello (5 characters - odd) beautiful (9 characters - odd) ...

Read More

Remove elements from a Dictionary using Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 25K+ Views

In JavaScript, there are multiple ways to remove elements from dictionary-like structures. This depends on whether you're working with plain objects, custom dictionary classes, or ES6 Maps. Using delete Operator with Objects For plain JavaScript objects acting as dictionaries, use the delete operator: const dict = { key1: "value1", key2: "value2", key3: "value3" }; console.log("Before deletion:", dict); delete dict.key2; console.log("After deletion:", dict); console.log("key2 exists:", "key2" in dict); Before deletion: { key1: 'value1', key2: 'value2', key3: 'value3' } After ...

Read More

Return index of first repeating character in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 290 Views

We are required to write a JavaScript function that takes in a string and returns the index of first character that appears twice in the string. If there is no such character then we should return -1. Following is our string: const str = 'Hello world, how are you'; Example Following is the code: const str = 'Hello world, how are you'; const firstRepeating = str => { const map = new Map(); for(let i = 0; i < str.length; i++){ ...

Read More

Search Element in a Dictionary using Javascript

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

In JavaScript, searching for elements in a dictionary (key-value pairs) can be accomplished using custom dictionary implementations or built-in ES6 Map objects. Both approaches provide efficient key-based lookups. Custom Dictionary Implementation Here's how to implement a get method that searches for a given key in a custom dictionary: get(key) { if(this.hasKey(key)) { return this.container[key]; } return undefined; } JavaScript objects are implemented like dictionaries internally, providing optimized key-value operations. This makes direct property access ...

Read More
Showing 3711–3720 of 6,519 articles
« Prev 1 370 371 372 373 374 652 Next »
Advertisements