
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

631 Views
Let’s say, we have an object with keys as string literals and their values as objects as well like this −const companies = { 'landwaves ltd': {employees: 1200, worth: '1.2m', CEO: 'Rajiv Bansal'}, 'colin & co': {employees: 200, worth: '0.2m', CEO: 'Sukesh Maheshwari'}, 'motilal biscuits': {employees: 975, worth: '1m', CEO: 'Rahul Gupta'}, 'numbtree': {employees: 1500, worth: '1.5m', CEO: 'Jay Kumar'}, 'solace pvt ltd': {employees: 1800, worth: '1.65m', CEO: 'Arvind Sangal'}, 'ambicure': {employees: 170, worth: '0.1m', CEO: 'Preetam Chawla'}, 'dis n dat': {employees: 540, worth: '1m', CEO: 'Mohit Sharma'}, }We are required to write ... Read More

749 Views
Let’s say, we have two arrays of equal lengths and are required to write a function that maps the two arrays into an object. The corresponding elements of the first array becomes the corresponding keys of the object and the elements of the second array become the value.We will reduce the first array, at the same time accessing elements of the second array by index. The code for this will be −Exampleconst keys = [ 'firstName', 'lastName', 'isEmployed', 'occupation', 'address', 'salary', 'expenditure' ]; const values = [ 'Hitesh', 'Kumar', false, ... Read More

235 Views
Let’s say, we have an array that contains some numbers, our job is to write a function that takes in the array and maps all the values relative to 0 to 100. Means that the greatest number should get replaced by 100, the smallest by 100 and all others should get converted to specific numbers between 0 and 100 according to the ratio.Following is the code for doing the same −Exampleconst numbers = [45.71, 49.53, 18.5, 8.38, 38.43, 28.44]; const mapNumbers = (arr) => { const max = Math.max(...arr); const min = Math.min(...arr); const diff = max ... Read More

332 Views
Let’s say, we have an array that contains some numbers, positive, negative, decimals and integers. We have to write a function that takes in an array and returns an array of square of all the positive integers from the original array.Let’s write the code for this function −Exampleconst arr = [1, -4, 6.1, 0.1, 2.6, 5, -2, 1.9, 6, 8.75, -7, 5]; const squareSum = (arr) => { return arr.reduce((acc, val) => { //first condition checks for positivity and second for wholeness of the number if(val > 0 && val % 1 === 0){ acc += val*val; }; return acc; },0); } console.log(squareSum(arr));OutputThe output in the console will be −87

665 Views
We have an array of Number / String literals that contain some duplicate values, we have to remove these values from the array without creating a new array or storing the duplicate values anywhere else.We will use the Array.prototype.splice() method to remove entries inplace, and we will take help of Array.prototype.indexOf() and Array.prototype.lastIndexOf() method to determine the duplicacy of any element.Exampleconst arr = [1, 4, 6, 1, 2, 5, 2, 1, 6, 8, 7, 5]; arr.forEach((el, ind, array) => { if(array.indexOf(el) !== array.lastIndexOf(el)){ array.splice(ind, 1); } }); console.log(arr);OutputThe output in the console will be −[ 4, 1, 5, 2, 6, 8, 7 ]

536 Views
Let’s say, here is an array that contains some data about the stocks sold and purchased by some company over a period of time.const transactions = [ ['AAPL', 'buy', 100], ['WMT', 'sell', 75], ['MCD', 'buy', 125], ['GOOG', 'sell', 10], ['AAPL', 'buy', 100], ['AAPL', 'sell', 100], ['AAPL', 'sell', 20], ['DIS', 'buy', 15], ['MCD', 'buy', 10], ['WMT', 'buy', 50], ['MCD', 'sell', 90] ];We want to write a function that takes in this data and returns an object of arrays with key as stock name (like ‘AAPL’, ‘MCD’) and value as array ... Read More

512 Views
We are given an array of n entries, of which only 2 are Numbers, all other entries are null. Something like this −const arr = [null, null, -1, null, null, null, -3, null, null, null];We are supposed to write a function that takes in this array and complete the arithmetic series of which these two numbers are a part. To understand this problem more clearly, we can think of these null values as blank space where we need to fill numbers so that the whole array forms an arithmetic progression.About Arithmetic ProgressionA series / array of numbers is said to ... Read More

142 Views
Provided an array of numbers, let’s say −const arr = [12, 54, 6, 23, 87, 4, 545, 7, 65, 18, 87, 8, 76];We are required to write a function that picks the minimum and maximum element from the array and returns an array of those two numbers with minimum at index 0 and maximum at 1.We will use the Array.prototype.reduce() method to build a minimum maximum array like this −Exampleconst arr = [12, 54, 6, 23, 87, 4, 545, 7, 65, 18, 87, 8, 76]; const minMax = (arr) => { return arr.reduce((acc, val) => { if(val < acc[0]){ acc[0] = val; } if(val > acc[1]){ acc[1] = val; } return acc; }, [Infinity, -Infinity]); }; console.log(minMax(arr));OutputThe output in the console will be −[ 4, 545 ]

390 Views
We are required to write Number.prototype.reverse() function that returns the reversed number of the number it is used with.For example −234.reverse() = 432; 6564.reverse() = 4656;Let’s write the code for this function. We will use a recursive approach like this −Exampleconst reverse = function(temp = Math.abs(this), reversed = 0, isNegative = this < 0){ if(temp){ return reverse(Math.floor(temp/10), (reversed*10)+temp%10,isNegative); }; return !isNegative ? reversed : reversed*-1; }; Number.prototype.reverse = reverse; const n = -12763; const num = 43435; console.log(num.reverse()); console.log(n.reverse());OutputThe output in the console will be −53434 -36721

256 Views
Digit root of some positive integer is defined as the sum of all of its digits. We are given an array of integers. We have to sort it in such a way that if a comes before b if the digit root of a is less than or equal to the digit root of b. If two numbers have the same digit root, the smaller one (in the regular sense) should come first. For example, 4 and 13 have the same digit root, however 4 < 13 thus 4 comes before 13 in any digitRoot sorting where both are present.For ... Read More