Web Development Articles

Page 268 of 801

ASCII to hex and hex to ASCII converter class in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 975 Views

In this tutorial, we'll create a JavaScript class that converts between ASCII and hexadecimal formats. This is useful for encoding text data, debugging, or working with binary protocols. Problem Statement We need to write a JavaScript class with two member functions: toHex: Takes an ASCII string and returns its hexadecimal equivalent toASCII: Takes a hexadecimal string and returns its ASCII equivalent For example, the string 'this is a string' should convert to hex '74686973206973206120737472696e67' and back to the original ASCII. How It Works ASCII to hex ...

Read More

Adding binary without converting in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 345 Views

Adding binary numbers without converting to decimal requires simulating manual binary addition with carry handling. This approach processes bits from right to left, just like traditional addition. Problem Statement We need to write a JavaScript function that takes two binary strings and returns their sum as a binary string, without converting to decimal numbers. Input: const str1 = '1101'; const str2 = '10111'; Expected Output: '100100' Algorithm Overview The solution works by: Reversing both strings to process from least significant bit Adding corresponding bits with carry propagation Building the ...

Read More

Counting adjacent pairs of words in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 374 Views

We are required to write a JavaScript function that takes in a string str that represents a sentence as the only argument. Our function should count and return the adjacent pair of identical words present in the string str. Our function should check the words ignoring their case, which means 'it' and 'It' should be counted as identical. Problem Statement For example, if the input to the function is: const str = 'This this is a a sample string'; The expected output should be: 2 Output Explanation: Because the ...

Read More

Crack Alphabets fight problem in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 219 Views

Problem Consider a situation where armies of two teams of alphabets are fighting each other. Each soldier has a specific weight based on their letter: Team A (Positive Weights) Soldier Weight A ...

Read More

Arranging lexicographically and removing whitespaces in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 191 Views

We need to write a JavaScript function that takes a string containing alphabets and whitespaces, then returns a new string with characters arranged in case-insensitive alphabetical order while removing whitespace and punctuation. Problem Statement Our function should iterate over the input string and concatenate characters into a new string following "case-insensitively-alphabetical-order-of-appearance" order. Whitespace and punctuation are simply removed. For example: Input: const str = 'some simple letter combination!'; Expected Output: abceeeeiiillmmmnnoooprssttt Solution Using Nested Loops The approach uses nested loops to iterate through each letter of the alphabet (a-z) ...

Read More

Checking for squared similarly of arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 180 Views

We are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and second argument respectively. Our function should return true if and only if every element in arr2 is the square of any element of arr1 irrespective of their order of appearance. For example, if the input to the function is: Input const arr1 = [4, 1, 8, 5, 9]; const arr2 = [81, 1, 25, 16, 64]; Output const output = true; Using Frequency Map Approach The ...

Read More

Validating alternating vowels and consonants in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 281 Views

Validating alternating vowels and consonants is a common string pattern validation problem. We need to check if vowels (a, e, i, o, u) and consonants alternate throughout the string. Problem Statement Write a JavaScript function that takes a string of English alphabets and returns true if vowels and consonants appear alternatingly, false otherwise. For example: Input: 'amazon' Output: true Explanation: a(vowel) → m(consonant) → a(vowel) → z(consonant) → o(vowel) → n(consonant) Solution const str = 'amazon'; const appearAlternatingly = (str = '') => { if (str.length === 0) ...

Read More

Finding minimum flips in a binary string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 261 Views

A monotonically increasing binary string consists of some number of '0's (possibly zero) followed by some number of '1's (also possibly zero). Examples include "000", "111", "0011", or "01". Problem Statement Given a binary string, we need to find the minimum number of flips required to make it monotonically increasing. We can flip any '0' to '1' or any '1' to '0'. For example, with input "00110", we can flip the last '0' to '1' to get "00111", which requires only 1 flip. Approach Using Dynamic Programming We use memoization to track the minimum flips ...

Read More

Binary subarrays with desired sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 160 Views

We need to write a JavaScript function that counts the number of subarrays in a binary array whose elements sum to a target value. Problem Statement Given a binary array arr and a target number, count all subarrays where the sum of elements equals the target. Example Input: const arr = [1, 0, 1, 0, 1]; const target = 2; Expected Output: 4 Explanation: The subarrays with sum 2 are: [1, 0, 1] (indices 0-2) [1, 0, 1] (indices 2-4) [0, 1, 0, 1] (indices 1-4) [1, 0, ...

Read More

Maximum subarray sum in circular array using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 269 Views

We need to write a JavaScript function that finds the maximum possible sum of a subarray in a circular array. In a circular array, the last element connects to the first element, creating additional subarray possibilities. Problem Statement Given an array of integers, find the maximum sum of any non-empty subarray. The array is considered circular, meaning we can wrap around from the end to the beginning. Example: Input: [2, -2, 3, -1] Output: 4 Explanation: Maximum subarray is [3, -1, 2] (wrapping around) Algorithm Approach The solution uses two key insights: ...

Read More
Showing 2671–2680 of 8,010 articles
« Prev 1 266 267 268 269 270 801 Next »
Advertisements