
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 10483 Articles for Web Development

372 Views
We are required to write a JavaScript function that takes in an array of nested arrays of Numbers and some false values (including 0) and some strings as wel. the function should return the product of number values present in the nested array.If the array contains some 0s, we should ignore them as well. Let’s write the code for this function −Exampleconst arr = [1, 5, 2, null, [ 2, 5, null, undefined, false, 5, [ 1, 3, false, 0, 2 ], 4, 2, false ], 4, 6, 0 ... Read More

127 Views
We are required to write a JavaScript function that takes in two strings and returns the count of the number of times the first string appears in the second stringLet’s say our string is −const main = 'This is the is main is string';We have to find the appearance of the below string in the above “main” string −const sub = 'is';Let’s write the code for this function −Exampleconst main = 'This is the is main is string'; const sub = 'is'; const countAppearances = (main, sub) => { const regex = new RegExp(sub, "g"); let count = ... Read More

2K+ Views
Let’s say, we have two arrays of numbers −const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34];We are required to write a JavaScript function that takes in two such arrays and returns the element from arrays that are not common to both.Let’s write the code for this function −ExampleFollowing is the code −const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34]; const unCommonArray = (first, second) => { const res = []; for(let i ... Read More

242 Views
A Pronic number is a number which is the product of two consecutive integers, that is, a number of the form n(n + 1).We are required to write a JavaScript function that takes in a number and returns true if it is a Pronic number otherwise returns falseLet’s write the code for this function −Exampleconst num = 90; const isPronic = num => { let nearestSqrt = Math.floor(Math.sqrt(num)) - 1; while(nearestSqrt * (nearestSqrt + 1)

580 Views
We are required to write a JavaScript function that takes in an array of positive as well as negative Numbers and changes the positive numbers to corresponding negative numbers and the negative numbers to corresponding positive numbers in place.Let’s write the code for this function −ExampleFollowing is the code −const arr = [12, 5, 3, -1, 54, -43, -2, 34, -1, 4, -4]; const changeSign = arr => { arr.forEach((el, ind) => { arr[ind] *= -1; }); }; changeSign(arr); console.log(arr);OutputFollowing is the output in the console −[ -12, -5, -3, 1, -54, 43, 2, -34, 1, -4, 4 ]

631 Views
Collinear PointsThree or more points that lie on the same straight line are called collinear points.And three points lie on the same if the slope of all three pairs of lines formed by them is equal.Consider, for example, three arbitrary points A, B and C on a 2-D plane, they will be collinear if −slope of AB = slope of BC = slope of acceptsSlope of a line −The slope of a line is generally given by the tangent of the angle it makes with the positive direction of x-axis.Alternatively, if we have two points that lie on the line, ... Read More

373 Views
We are required to write a JavaScript function that takes in a string and replaces the adjacent words of that string.For example: If the input string is −const str = "This is a sample string only";Then the output should be −"is This sample a only string"Let’s write the code for this function −ExampleFollowing is the code −const str = "This is a sample string only"; const replaceWords = str => { return str.split(" ").reduce((acc, val, ind, arr) => { if(ind % 2 === 1){ return acc; } ... Read More

199 Views
We are required to write a JavaScript function that takes in two numbers, say m and n and returns two numbers whose sum is n and product is m. If there exist no such numbers, then our function should return falseLet’s write the code for this function −Exampleconst perfectNumbers = (sum, prod) => { for(let i = 0; i < (sum / 2); i++){ if(i * (sum-i) !== prod){ continue; }; return [i, (sum-i)]; }; return false; }; // 12 12 are not two distinct numbers console.log(perfectNumbers(24, 144)); console.log(perfectNumbers(14, 45)); console.log(perfectNumbers(21, 98));OutputFollowing is the output in the console −false [ 5, 9 ] [ 7, 14 ]

127 Views
We are required to write a JavaScript function that takes in array of strings and delete every one of the two string that start with the same letter.For example, If the actual array is −const arr = ['Apple', 'Jack' , 'Army', 'Car', 'Jason'];Then, we have to keep only one string in the array, so one of the two strings starting with A should get deleted. In the same way, the logic follows for the letter J in the above array.Let’s write the code for this function −Exampleconst arr = ['Apple', 'Jack' , 'Army', 'Car', 'Jason']; const delelteSameLetterWord = arr => ... Read More

534 Views
In this article, we will learn to convert an array with a null value to a string in Javascript. Handling arrays containing null, undefined, and falsy values in JavaScript is a frequent challenge. The default methods might not behave as expected when converting such arrays to strings, requiring custom solutions for meaningful string representations. Problem Statement Given an array containing null, undefined, empty strings, and other values, the task is to concatenate its elements into a single string while excluding the unwanted values. Following is our array, with some null and undefined values − Input ["Here", "is", null, "an", undefined, ... Read More