
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 9150 Articles for Object Oriented Programming

506 Views
We are required to write a JavaScript function that takes a string and an array of strings.Our function should return a new string, where all the occurrences of the word in the string that are present in the array are replaced by a whitespace.Our function should use the String.prototype.replace() method to solve this problem.ExampleThe code for this will be −var excludeWords = ["A", "ABOUT", "ABOVE", "ACROSS", "ALL", "ALONG", "AM", "AN", "AND", "ANY", "ASK", "AT", "AWAY", "CAN", "DID", "DIDN'T", "DO", "DON'T", "FOR", "FROM", "HAD", "HAS", "HER", "HIS", "IN", "INTO", "IS", "IT", "NONE", "NOT", "OF", "ON", "One", "OUT", "SO", "SOME", "THAT", "THE", ... Read More

273 Views
Suppose, we have an array of Numbers represented by strings like this −const arr = ["1.1", "1.2", "1.3", "2.1", "2.2", "3.1", "3.2", "3.3", "4.1", "4.2"];We are required to write a JavaScript function that takes in one such array and groups all the strings starting with same number in a common subarray.Therefore, the output of our function should look like −const output = [["1.1", "1.2", "1.3"], ["2.1", "2.2"], ["3.1", "3.2", "3.3"], ["4.1", "4.2"]];ExampleThe code for this will be −const arr = ["1.1", "1.2", "1.3", "2.1", "2.2", "3.1", "3.2", "3.3", "4.1", "4.2"]; const groupSimilarStarters = arr => { let res = ... Read More

249 Views
Suppose, we have an array of Numbers like this −const arr = [1, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];We are required to write a JavaScript function that takes in one such array and chunks the array into quarterly and yearly groups intermediately.The groups for the above array should look something like this −const quarterly = [[1, 2, 2], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20]]; const yearly = [[1, 2, 2, 4, 5, 6, 7, 8, 9, ... Read More

1K+ Views
Suppose we have the number 12145. We are required to write a function that maps the digits of the number to English alphabets according to the following norms. The alphabets are to be mapped according to the 1 based index, like 'a' for 1 and 'b' for 2 'c' for 3 and so on.There can be several ways for mapping a number. Let's take the above number 121415 for example, It can be mapped as −12145->1, 2, 1, 4, 5->a, b, a, d, eIt also can be −12145->12, 1, 4, 5->l, a, d, eIt can also be −12145->12, 14, 5->l, ... Read More

797 Views
We are required to write a JavaScript function that takes in a string and returns the shortest word from the string.For example: If the input string is −const str = 'This is a sample string';Then the output should be −const output = 'a';ExampleThe code for this will be −const str = 'This is a sample string'; const findSmallest = str => { const strArr = str.split(' '); const creds = strArr.reduce((acc, val) => { let { length, word } = acc; if(val.length < length){ length = val.length; ... Read More

309 Views
Suppose we have a JSON object that have information about the location of some cities of some countries like this −const countryInfo = { country: [{ name: "Bangladesh", province: [{ name:"Dhaka", city: [{ name:"Tangail", lat: '11' }, { name:"Jamalpur", lat: '12' }] }, { name: "Khulna", ... Read More

2K+ Views
We are given two arrays: (arr1 and arr2) −arr1 contains some literal values.arr2 contains objects that map some literal values.We are required to write a JavaScript function that takes in two such arrays. Then the function should return an array of all the elements from arr1 that are not mapped by objects in arr2.ExampleThe code for this will be −const arr1 = [111, 222, 333, 444]; const arr2 = [ { identifier: 111 }, { identifier: 222 }, { identifier: 444 }, ]; const getAbsentValues = (arr1, arr2) => { let res = []; res = arr1.filter(el => { return !arr2.find(obj => { return el === obj.identifier; }); }); return res; }; console.log(getAbsentValues(arr1, arr2));OutputThe output in the console −[ 333 ]

862 Views
We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n as the second argument. The number n will always be less than or equal to the length of the array.Our function should return an array of the sum of all elements of all the possible subarrays of length n from the original array.For example, If the input is −const arr = [2, 6, 4]; const n = 2;Then the output should be −const output = [8, 10, 6];ExampleThe code for this will be −const arr = ... Read More

285 Views
We are required to write a JavaScript function that takes in any number of arrays of numbers. Then the function should return an object that returns a frequency map indicating how many times each element has appeared checking in all the array.For example, If the arrays are −const a = [23, 45, 21], b = [45, 23], c = [21, 32], d = [23], e= [32], f=[50, 54];Then the output should be −const output = { "21": 2, "23": 3, "32": 2, "45": 2, "52": 1, "54": 1, "23, 45": 2, "23, ... Read More

862 Views
Suppose we have an array of objects like this −const arr = [ { duration: 10, any: 'fields' }, { duration: 20, any: 'other fields' }, { duration: 15, any: 'some other fields' } ];We are required to write a JavaScript function that takes in one such array and returns the summed result of the duration properties of all the objects.For the above array, the output should be 45.ExampleThe code for this will be −const arr = [ ... Read More