AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 345 of 840

Finding alphabet from ASCII value without using library functions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 553 Views

Problem We are required to write a JavaScript function that takes in a number representing an ASCII value. Our function should return the corresponding alphabet character for that ASCII value (if it exists), or -1 otherwise. The condition here is that we cannot use any built-in function like String.fromCharCode() that directly converts ASCII values to characters. Understanding ASCII Values ASCII values for alphabetic characters follow these ranges: Uppercase letters: A-Z have ASCII values 65-90 Lowercase letters: a-z have ASCII values 97-122 Example Following is the code: const num = ...

Read More

Check if an array is growing by the same margin in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 193 Views

We are required to write a JavaScript function that takes in an array of numbers. Our function should return true if the difference between all adjacent elements is the same positive number, false otherwise. Syntax function growingMarginally(arr) { // Check if array has consistent positive differences // Return true/false } Example: Basic Implementation The code for this will be − const arr = [4, 7, 10, 13, 16, 19, 22]; const growingMarginally = arr => { if(arr.length

Read More

Substring in infinitely extended string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 217 Views

We are required to write a JavaScript function that takes in a string of characters as the first argument and a start index and end index as second and third argument respectively. The function should find, had that string, provided as the first argument, been extended forever by appending the same string at end each time, what would have been the substring encapsulated by the start index and the end index. For example, if we have the string 'helloo' repeated infinitely like 'hellooheloohelloo...', we can extract any substring using start and end indices. Understanding the Problem If ...

Read More

Checking if a key exists in a JavaScript object

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 556 Views

We are required to illustrate the correct way to check whether a particular key exists in an object or not. Before moving on to the correct way let's first examine an incorrect way and see how it's actually incorrect. Way 1: Checking for undefined value (incorrect way) Due to the volatile nature of JavaScript, we might want to check for the existence of key in an object like this: const obj = { name: 'Rahul' }; // Incorrect approaches console.log(!obj['fName']); ...

Read More

Finding all valid word squares in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 313 Views

What is a Word Square? A word square consists of a set of words written out in a square grid, such that the same words can be read both horizontally and vertically. This means the character at position (i, j) must equal the character at position (j, i). For instance, one valid word square is: H E A R T E M B E R A B U S E R E S I N T R E N D We need to write a JavaScript function that takes an array of words and ...

Read More

Even index sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 652 Views

We need to write a JavaScript function that calculates the sum of all integers at even indices (0, 2, 4, etc.) in an array, then multiplies this sum by the last element of the array. Problem Statement Given an array of integers, find the sum of elements at even indices and multiply by the last element. Input: [4, 1, 6, 8, 3, 9] Even indices: 0, 2, 4 → elements: 4, 6, 3 Sum: 4 + 6 + 3 = 13 Last element: 9 Result: 13 × 9 = 117 Solution const ...

Read More

Finding the length of longest vowel substring in a string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 581 Views

Problem We are required to write a JavaScript function that takes in a string. Our function should return the length of the longest contiguous substring that contains only vowels. Approach The solution uses a sliding window approach to track consecutive vowels. We maintain two variables: cur for the current vowel sequence length and max for the longest sequence found so far. Example Following is the code − const str = 'schooeal'; const findLongestVowel = (str = '') => { let cur = 0; let max ...

Read More

Validate Tutorialspoint URL via JavaScript regex?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 259 Views

To validate a TutorialsPoint URL using JavaScript, you can use regular expressions to check if the URL matches the expected domain pattern and extract specific parts of the URL. Regular Expression Pattern The regex pattern /^https?:\/\/(tutorialspoint\.com)\/(.*)$/ breaks down as follows: ^ - Start of string https? - Matches "http" or "https" :\/\/ - Matches "://" (tutorialspoint\.com) - Captures the domain (escaped dot) \/ - Matches forward slash (.*)$ - Captures everything after the domain until end of string Example function validateTutorialspointURL(myURL) { var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/; ...

Read More

Extract arrays separately from array of Objects in JavaScript

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

Suppose, we have an array of objects like this − const arr = [{ name : 'Client 1', total: 900, value: 12000 }, { name : 'Client 2', total: 10, value: 800 }, { name : 'Client 3', total: 5, value : 0 }]; We are required to write a JavaScript function that takes in one such array and extracts a separate array for each object property. Therefore, ...

Read More

Primality test of numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 584 Views

A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. All other natural numbers greater than 1 are called composite numbers. A primality test is an algorithm for determining whether an input number is prime. We are required to write a JavaScript function that takes in a number and checks whether it is a prime or not. Basic Primality Test Algorithm The most efficient approach is to check divisibility up to the square root of the number, skipping even numbers after checking for 2. ...

Read More
Showing 3441–3450 of 8,392 articles
« Prev 1 343 344 345 346 347 840 Next »
Advertisements