
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

859 Views
We are required to write a JavaScript function that takes in an array of strings as the first argument and two numbers as second and third argument respectively.The purpose of our function is to sort the array. But we have to sort only that part of the array that falls between the start and end indices specified by second and third argument. Keeping all the other elements unchanged.For example −const arr = ['z', 'b', 'a']; sortBetween(arr, 0, 1);This function should sort the elements at 0 and 1 index only. And the array should become −const output = ['b', 'z', 'a'];Exampleconst ... Read More

323 Views
We are required to write a function that finds the mean of the three scores passed to it and returns the letter value associated with that grade according to the following table.Exampleconst findGrade = (...scores) => { const { length } = scores; const sum = scores.reduce((acc, val) => acc + val); const score = sum / length; if (score >= 90 && score = 80 ) { return 'B'; } else if (score >= 70 ) { return 'C'; } else if (score >= 60) { return 'D'; } else{ return 'F'; }; } console.log(findGrade(5,40,93)); console.log(findGrade(30,85,96)); console.log(findGrade(92,70,40));OutputAnd the output in the console will be −F C D

1K+ Views
In JavaScript, when dealing with arrays of objects, it’s common to need to extract specific values based on object properties and count how many unique occurrences exist for a particular property. Whether you're processing a list of users, products, or any other data structure, counting unique elements by a property is a useful operation.In this article, we'll discuss how to count the number of unique elements in an array of objects based on a specific property using a few different techniques. Problem Statement You have an array of objects representing users, each with properties like name, age, gender, etc. You ... Read More

3K+ Views
Suppose we have an array of alphanumeric strings like this −const arr = ['A1', 'A10', 'A11', 'A12', 'A3A', 'A3B', 'A3', 'A4', 'B10', 'B2', 'F1', '1', '2', 'F3'];We are required to write a JavaScript function that in one such array as one and the only argument.And the function should sort this array inplace −The strings that contains only numbers should come first sorted in increasing order.The strings containing a combination of alphabets and numbers should be sorted first according to alphabets and then according to numbers in increasing order.Therefore, the output should look like −const output = ['1', '2', 'A1', 'A2', ... Read More

486 Views
We are required to compare, and get the difference, between two arrays containing single character strings appearing multiple times in each array.Example of two such arrays are −const arr1 = ['A', 'C', 'A', 'D']; const arr2 = ['F', 'A', 'T', 'T'];We will check each character at the same position and return only the parts who are different.Exampleconst arr1 = ['A', 'C', 'A', 'D']; const arr2 = ['F', 'A', 'T', 'T']; const findDifference = (arr1, arr2) => { const min = Math.min(arr1.length, arr2.length); let i = 0; const res = []; while (i < min) { ... Read More

237 Views
Suppose, we have an array of arrays like this −const arr = [ [1, 0], [0, 1], [0, 0] ];We are required to write a JavaScript function that takes in one such array as the first argument and an array of exactly two Numbers as the second argument.Our function should check whether or not the array given by second input exists in the original array of arrays or not.Exampleconst arr = [ [1, 0], [0, 1], [0, 0] ]; const sub = [0, 0]; const matchEvery = (arr, ind, sub) => arr[ind].every((el, i) => el == sub[i]); ... Read More

410 Views
Suppose we have two arrays of strings. The first array contains exactly 12 strings, one for each month of the year like this −const year = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];The second array, contains exactly two strings, denoting a range of months like this −const monthsRange = ["aug", "oct"];We are required to write a JavaScript function that takes in two such arrays. Then the function should pick all the months from the first array that falls in the range specified by the second range arrays.Like for the above arrays, the output should be ... Read More

630 Views
Suppose, we have an array of objects and an array of strings like this −Exampleconst orders = [ { status: "pending"}, { status: "received" }, { status: "sent" }, { status: "pending" } ]; const statuses = ["pending", "sent", "received"];We are required to write a JavaScript function that takes in two such arrays. The purpose of the function should be to sort the orders array according to the elements of the statuses array.Therefore, objects in the first array should be arranged according to the strings in the second array.Exampleconst orders = [ { status: "pending" ... Read More

2K+ Views
We are required to write a JavaScript function that takes in an array of intervals (start and end time like this −const arr = [ { start: '01:00', end: '04:00' }, { start: '05:00', end: '08:00' }, { start: '07:00', end: '11:00' }, { start: '09:30', end: '18:00' }, ];Our function should iterate through this array of objects and check all elements of the array against the others.If an overlapping interval is found, the iteration stops and true is returned, Otherwise false. By overlapping intervals, we mean time intervals that have some time in common.Exampleconst arr ... Read More

396 Views
We are required to write a JavaScript function that takes in a string of any length. The function should then count the number of words in that string.Exampleconst str = 'THis is an example string'; const findWords = (str = '') => { if(!str.length){ return 0; }; let count = 1; for(let i = 0; i < str.length; i++){ if(str[i] === ' '){ count++; }; }; return count; }; console.log(findWords(str));OutputAnd the output in the console will be −5