- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 6683 Articles for Javascript
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
367 Views
We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument. The function should then construct and return a new array that contains only those elements from the original array that contains an even number of digits.For example −If the input array is −const arr = [12, 6, 123, 3457, 234, 2];Then the output should be −const output = [12, 3457];ExampleThe code for this will be − Live Democonst arr = [12, 6, 123, 3457, 234, 2]; const findEvenDigitsNumber = (arr = []) => { const res = []; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
196 Views
We are required to write a JavaScript function that takes in a number, num as the only argument. The function should first construct an array of n elements based on the following rule −arr[i] = (2 * i) + 1;Therefore, if the input number is 5, then the array should be −const arr = [1, 3, 5, 7, 9];Our function is supposed to calculate and return the minimum number of steps it should take so that all the elements of the array become equal.Let us now define one step −One valid step consists of choosing any two numbers from the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
279 Views
We are required to write a JavaScript function that takes in a binary array (an array that consists of 0 or 1 only) as the only argument.The function should find the length of that consecutive subarray of the array that consists of only 1 and return it.For example −If the input array is −const arr = [1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1];Then the output should be −const output = 4;We will use the sliding window algorithm to capture the largest window (largest in size) that consists of only 1.ExampleThe code for this ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
119 Views
We are required to write a JavaScript function that takes in four arguments. The four arguments will all be arrays of exactly two numbers representing the coordinates of four vertices of a quadrilateral or any figure (closed or unclosed) on a plane.The task of our function is to determine whether or not the four vertices form a square.If they do form a square, we should return true, false otherwise.For example −If the input coordinates are −const c1 = [1, 0]; const c2 = [-1, 0]; const c3 = [0, 1]; const c4 = [0, -1];Then the output should be −const ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
337 Views
We are required to write a JavaScript function that takes in three arrays of integers all sorted in an increasing order. The function should then construct and return an array that contains only those elements that present in all three arrays.For example −If the input arrays are −const arr1 = [4, 7, 8, 11, 13, 15, 17]; const arr2 = [1, 3, 4, 13, 18]; const arr3 = [2, 4, 7, 8, 9, 10, 13];Then the output should be −const output = [4, 13];ExampleThe code for this will be − Live Democonst arr1 = [4, 7, 8, 11, 13, 15, 17]; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
128 Views
Anagram arrays:One array is an anagram of another if we can randomise the elements of that array to achieve the other array.For example −[1, 2, 3] and [2, 1, 3] are anagrams of each other.Suppose, we have two arrays, arr1 and arr2 which are anagrams of each other.We are required to write a JavaScript function that takes in these two arrays and returns a new mapping array of the same length as arr1 and arr2. The mapping array should contain the index of elements of the arr1 array as they are present in the arr2 array.For example −If the two ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
203 Views
Suppose we have a keyword, which instead of the traditional qwerty type key mapping, maps keys simply according to the english alphabetic order i.e., abcde...Before we dive into the problem, we have to make the following two assumptions −Currently our fingertip is placed at index 0, i.e., the key 'aThe time taken to move from one key to some other is the absolute difference of their index, for example the time taken to move from 'a' to 'k' will be |0 - 10| = 10We are required to write a JavaScript function that takes in a string of english lowercase ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
153 Views
We are required to write a JavaScript function that takes in a number as the first and the only argument. The function should then square every digit of the number, append them and yield the new number.For example −If the input number is −const num = 12349;Then the output should be −const output = 1491681;because '1' + '4' + '9' + '16' + '81' = 1491681ExampleThe code for this will be − Live Democonst num = 12349; const squareEvery = (num = 1) => { let res = '' const numStr = String(num); const numArr = numStr.split(''); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
265 Views
We are required to write a JavaScript function that takes in an array of string words as the first argument. The second argument to the function will be a string containing all 26 English lowercase alphabets but in some random scrambled order.The task of our function is to check whether the words in the array are placed lexicographically correctly according to the order specified by the second argument. If it is so, we should return true, false otherwise.For example −If the input array of words and the order is −const arr = ['this', 'is', 'something', 'mad']; const order = 'hdetljnopqabcuvwxfgirsykmz';Then ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
511 Views
We are required to write a JavaScript function that takes in a string str as the first argument and an array of strings, arr as the second argument. We need to add a closed pair of paragraph tag and to wrap the substrings in str that exist in arr. If two such substrings overlap, we need to wrap them together by only one pair of closed paragraph tag.Also, if two substrings wrapped by paragraph tags are consecutive, we need to combine them.For example −If the input string and the array are −const str = 'kkkllmm'; const arr = ... Read More