
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

134 Views
ProblemWe are required to write a JavaScript function that takes in the head of a linked list as the first and the only argument.Our function should return the value stored in the middlemost node of the list. And if there are two middlemost nodes, we should return the second one of them.For example, if the list is like this:Input[4, 6, 8, 9, 1]Outputconst output = 8;Following is the code:Exampleclass Node { constructor(data) { this.data = data; this.next = null; }; }; class LinkedList { constructor() { this.head = ... Read More

385 Views
ProblemWe are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and the second argument.The sum of elements in arr1 and arr2 are different. Our function should pick one element from the first array and push it in the second array and pick one element from the second array and push it in the first array such that the sum of the elements of both the arrays become equal. We should return an array of these two elements.For example, if the input to the function isInputconst arr1 = [1, 2, ... Read More
311 Views
In the realm of JavaScript programming, the ability to reverse the alphabets within a string holds significant importance for developers seeking to manipulate textual data in innovative ways. JavaScript, a versatile and widely used scripting language, provides a multitude of techniques and functions to accomplish this task efficiently. Reversing alphabets within a string entails rearranging the characters in a reverse order, transforming the original sequence into its mirror image. In this article, we will embark upon a journey to explore the intricacies of reversing alphabets in a string using JavaScript, delving into the lesser-known methods and algorithms that empower developers ... Read More

202 Views
ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, as the first and the only argument.We can consider this array arr to be a circular array, which means the last element of the array will be followed by the first. Our function should find and return the maximum possible sum of a non-empty subarray of arr.For example, if the input to the function isInputconst arr = [2, -2, 3, -1];Outputconst output = 4;Output ExplanationBecause the desired subarray is [3, -1, 2]Example Live Democonst arr = [2, -2, 3, -1]; const maxSubarraySumCircular = (arr = ... Read More

120 Views
ProblemWe are required to write a JavaScript function that takes in a string, str, which consists of only ‘[‘ or ‘]’. Our function is supposed to add the minimum number of square brackets ( '[' or ']', and in any positions ) so that the resulting bracket combination string is valid. And lastly, we should return the smallest number of brackets added.For example, if the input to the function isInputconst str = '[]]';Outputconst output = 1;Output ExplanationBecause, if we add ‘[‘ to the starting, the string will be balanced.Exampleconst findAdditions = (str = '') => { let left = 0 ... Read More

107 Views
ProblemWe are required to write a JavaScript function that takes in a binary array, arr, as the first argument, and a number, target, as the second argument.Our function is supposed to count the number of subarrays that exists in the array arr, the sum of whose elements is equal to count. We should finally return this count.For example, if the input to the function isInputconst arr = [1, 0, 1, 0, 1]; const target = 2;Outputconst output = 4;Output ExplanationBecause the desired subarrays are:[1, 0, 1][1, 0, 1, 0] [0, 1, 0, 1] [1, 0, 1]Example Live Democonst arr = [1, ... Read More

201 Views
Monotonically Increasing String:A string of '0's and '1's is monotonically increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.)ProblemWe are required to write a JavaScript function that takes in a binary string, str, as the first and the only argument.We can flip any ‘0’ to ‘1’ or any ‘1’ to ‘0’ present in the string. Our function should return the minimum number of flips to make S monotonically increasing.For example, if the input to the function isInputconst str = '00110';Outputconst output = 1;Output ExplanationBecause if we flip the last ... Read More

217 Views
ProblemWe are required to write a JavaScript function that takes in a string of English alphabets, str, as the first and the only argument. Our function should return true if and only if the vowels and consonants appear alternatingly in the input string, false otherwise.For example, if the input to the function is −Inputconst str = 'amazon';Outputconst output = true;Output ExplanationBecause the vowels and consonants appear alternatingly in the string ‘amazon’.ExampleFollowing is the code − Live Democonst str = 'amazon'; const appearAlternatingly = (str = '') => { return str.split('').every((v, i)=>{ if (/[aeiou]/.test(str[0])){ ... Read More

117 Views
ProblemWe 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 −Inputconst arr1 = [4, 1, 8, 5, 9]; const arr2 = [81, 1, 25, 16, 64];Outputconst output = true;ExampleFollowing is the code − Live Democonst arr1 = [4, 1, 8, 5, 9]; const arr2 = [81, 1, 25, 16, 64]; const isSquared ... Read More

857 Views
In this article, we create a function that can take a string in any format. Such as normal case, snake case, pascal case or any other into camelCase in JavaScript. camelCase is a writing style where each word within a phrase is capitalized, except for the first word, and there are no spaces or punctuation. Let us understand through some sample example of I/O Scenario − Sample Input - const str = 'New STRING'; Sample Output - const output = 'newString'; Converting any case to camelCase in JavaScript Converting any case to camelCase in JavaScript is quite easy. Let's ... Read More