Front End Technology Articles

Page 213 of 652

Removing comments from array of string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 432 Views

We are required to write a JavaScript function that takes in array of strings, arr, as the first argument and an array of special characters, starters, as the second argument. The starter array contains characters that can start a comment. Our function should iterate through the array arr and remove all the comments contained in the strings. Problem Example For example, if the input to the function is: const arr = [ 'red, green !blue', 'jasmine, #pink, cyan' ]; const starters = ['!', '#']; Then the output ...

Read More

Sum JavaScript arrays repeated value

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 364 Views

Suppose, we have an array of objects like this − const arr = [ {'TR-01':1}, {'TR-02':3}, {'TR-01':3}, {'TR-02':5}]; We are required to write a JavaScript function that takes in one such array and sums the value of all identical keys together. Therefore, the summed array should look like − const output = [ {'TR-01':4}, {'TR-02':8}]; Method 1: Using In-Place Modification This approach modifies the original array by tracking duplicate keys and summing their values: const arr = [ {'TR-01':1}, {'TR-02':3}, {'TR-01':3}, {'TR-02':5}]; const sumDuplicate = arr => ...

Read More

Breaking camelCase syntax in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 320 Views

We need to write a JavaScript function that takes a camelCase string and converts it into a readable format by adding spaces before uppercase letters. Our function should construct and return a new string that splits the input string using a space between words. Problem Example For example, if the input to the function is: Input const str = 'thisIsACamelCasedString'; Expected Output 'this Is A Camel Cased String' Solution Using String Iteration The approach iterates through each character and adds a space before uppercase letters (except the first character): ...

Read More

Compare arrays using Array.prototype.every() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 239 Views

We are required to write a JavaScript function that takes in two arrays of literals. Then our function should return true if all the elements of first array are included in the second array, irrespective of their count, false otherwise. We have to use Array.prototype.every() method to make these comparisons. Syntax array.every(callback(element, index, array), thisArg) How Array.every() Works The every() { const areEqual = arr1.every(el => { return arr2.includes(el); }); return areEqual; }; ...

Read More

Sorting numbers based on their digit sums in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 629 Views

We are required to write a JavaScript function that takes in an array of positive integers and sorts them based on their digit sums in descending order. Numbers with higher digit sums appear first. Problem Statement Given an array of positive integers, sort the array so that numbers with the highest digit sum come first, followed by numbers with lesser digit sums. For example, if the input array is: const arr = [5, 34, 1, 13, 76, 8, 78, 101, 57, 565]; The output should be: [565, 78, 76, 57, 8, ...

Read More

Comparing array elements keeping count in mind in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 211 Views

Suppose, we have two arrays of literals that contain the same number of elements. We are supposed to write a function that checks whether or not the both arrays contain the same elements appearing for the same number of times. If the arrays fulfil this condition, we return true, false otherwise. We will create a copy of the second array, and start iterating over the first array. As we iterate, we will keep deleting the elements from the second array that are present in first array. If during iteration we encounter any element that isn't present in second ...

Read More

Converting alphabets to Greek letters in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 719 Views

Converting alphabets to Greek letters in JavaScript requires creating a mapping between English and Greek characters, then replacing each character accordingly. Character Mapping First, let's establish the mapping between English and Greek letters: A=α (Alpha) B=β (Beta) D=δ (Delta) E=ε (Epsilon) I=ι (Iota) K=κ (Kappa) N=η (Eta) O=θ (Theta) P=ρ (Rho) R=π (Pi) T=τ (Tau) U=μ (Mu) V=υ (Upsilon) W=ω ...

Read More

Sort nested array containing objects ascending and descending according to date in JavaScript

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

Suppose we have a JSON Object that contains a nested array like this: const arr = { "DATA": [ { "BookingID": "9513", "DutyStart": "2016-02-11 12:00:00" }, { "BookingID": "91157307", "DutyStart": "2016-02-11 13:00:00" }, { "BookingID": "95117317", "DutyStart": "2016-02-11 13:30:00" ...

Read More

Search a complex object by id property in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 490 Views

Suppose we have a complex JSON Object like this − const obj = { "id": "0001", "fieldName": "sample1", "fieldValue": "0001", "subList": [ { "id": 1001, "fieldName": "Sample Child 1", "fieldValue": "1001", "subList": [] }, { "id": 1002, "fieldName": "Sample Child 2", ...

Read More

Computing Ackerman number for inputs in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 472 Views

The Ackermann Function is a classic example of a recursive function that grows extremely quickly. It's notable for being a total computable function that is not primitive recursive, making it an important concept in theoretical computer science. Problem Statement We need to write a JavaScript function that takes two non-negative integers, m and n, and returns the Ackermann number A(m, n) defined by the following mathematical definition: A(m, n) = n+1 if m=0 A(m, n) = A(m-1, 1) if m>0 and n=0 A(m, n) = A(m-1, A(m, n-1)) if m>0 and n>0 Implementation ...

Read More
Showing 2121–2130 of 6,519 articles
« Prev 1 211 212 213 214 215 652 Next »
Advertisements