Front End Technology Articles

Page 192 of 652

Encrypting censored words using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 328 Views

This tutorial demonstrates how to encrypt or mask censored words in JavaScript by applying specific transformation rules to convert regular text into a masked format. Problem We need to write a JavaScript function that takes in a string and converts it according to the following rules: All words should be in uppercase Every word should end with '!!!!' Any letter 'a' or 'A' should become '@' Any other vowel (E, I, O, U) should become '*' Solution Here's the implementation of the word masking function: const str = 'ban censored words'; ...

Read More

Reversing the even length words of a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 421 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an even number of characters in them. Let's say the following is our string: const str = 'This is an example string'; We want to reverse the even length words of the above string i.e. reverse the following words: This (4 characters) is (2 characters) an (2 characters) string (6 characters) The word "example" has 7 characters (odd length), so it remains unchanged. Syntax ...

Read More

Moving every alphabet forward by 10 places in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 304 Views

Problem We need to write a JavaScript function that takes a string of English alphabets and shifts every letter forward by 10 positions. When a letter goes past 'z', it wraps around to start again at 'a'. Example Following is the code − const str = 'sample string'; const moveStrBy = (num = 10) => { return str => { const calcStr = (ch, code) => String .fromCharCode(code + (ch.charCodeAt(0) - ...

Read More

Differences in two strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 530 Views

We are required to write a JavaScript function that takes in two strings and find the number of corresponding dissimilarities in the strings. The corresponding elements will be dissimilar if they are not equal at the same position. Example Strings Let's say the following are our strings: const str1 = 'Hello world!!!'; const str2 = 'Hellp world111'; In this case, we need to compare each character at the same index and count how many positions have different characters. Method 1: Using a For Loop const str1 = 'Hello world!!!'; const str2 ...

Read More

Finding the date at which money deposited equals a specific amount in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 176 Views

When calculating compound interest over time, you may need to determine the exact date when your deposited money will reach a target amount. This problem involves daily compounding at a given annual interest rate. Problem Statement Given an initial deposit amount, a target amount, and an annual interest rate, we need to find the date when the deposited money (with daily compounding) will equal or exceed the target amount. The calculation starts from January 1st, 2021, with interest compounded daily at a rate of p percent divided by 360 days. Solution Approach The solution uses a ...

Read More

Finding the index of the first repeating character in a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 660 Views

We are required to write a JavaScript function that takes in a string and returns the index of the first character that appears twice in the string. If there is no such character then we should return -1. Let's say the following is our string − const str = 'Hello world, how are you'; We need to find the index of the first repeating character. Understanding the Problem In the string "Hello world, how are you", we need to find which character repeats first. The character 'l' appears at index 2 and again ...

Read More

Checking for vowels in array of numbers using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 290 Views

We are required to write a JavaScript function that takes in an array of numbers. If in that array there exists any number which is the char code of any vowel in ASCII, we should switch that number to the corresponding vowel and return the new array. Understanding ASCII Character Codes In ASCII, vowels have specific character codes: 'a' = 97 'e' = 101 'i' = 105 'o' = 111 'u' = 117 Example Let's create a function that converts ASCII codes to vowels when they match: const arr = [5, 23, ...

Read More

Column sum of elements of 2-D arrays in JavaScript

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

We have an array of arrays and are required to write a function that takes in this array and returns a new array that represents the sum of corresponding elements of original array. If the original array is: [ [43, 2, 21], [1, 2, 4, 54], [5, 84, 2], [11, 5, 3, 1] ] Then the output should be: [60, 93, 30, 55] This means we add all elements at index 0 (43+1+5+11=60), all elements at index 1 (2+2+84+5=93), ...

Read More

Checking if all array values are smaller than a limit using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 494 Views

Problem We are required to write a JavaScript function that takes in an array of numbers and a number. We should return true if all the numbers in the array are smaller than the number given as second argument, false otherwise. Using Array.every() Method The Array.every() method tests whether all elements in the array pass the test implemented by the provided function. It returns true if all elements satisfy the condition, false otherwise. Example 1: All Values Smaller Following is the code − const arr = [5, 34, 23, 14, 78, 45, 78]; const limit = ...

Read More

Finding smallest number that satisfies some conditions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 275 Views

We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n-digit number which is a multiple of all the elements specified in the array. If there exist no such n-digit element then we should return the smallest such element. For example: If the array is − const arr = [12, 4, 5, 10, 9] For both n = 2 and n = 3, we need to find the smallest number ...

Read More
Showing 1911–1920 of 6,519 articles
« Prev 1 190 191 192 193 194 652 Next »
Advertisements