
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

2K+ Views
Suppose we have an array of objects that contains data about some houses and price like this −const arr = [ { "h_id": "3", "city": "Dallas", "state": "TX", "zip": "75201", "price": "162500" }, { "h_id": "4", "city": "Bevery Hills", "state": "CA", "zip": "90210", "price": "319250" }, { "h_id": "5", "city": "New York", "state": "NY", ... Read More

264 Views
We are required to write a JavaScript function that takes in an array of Numbers. Our function should iterate through the array and pick the greatest (largest) element from the array and return that element.ExampleThe code for this will be −const arr = [5, 3, 20, 15, 7]; const findGreatest = (arr = []) => { let greatest = -Infinity; if(!arr?.length){ return null; }; for(let i = 0; i < arr.length; i++){ const el = arr[i]; if(el < greatest){ continue; }; greatest = el; }; return greatest; }; console.log(findGreatest(arr));OutputAnd the output in the console will be −20

501 Views
Suppose, we have a nested array of arrays like this −const arr = [ ["LEFT", "RIGHT", "RIGHT", "BOTTOM", "TOP"], ["RIGHT", "LEFT", "TOP"], ["TOP", "LEFT"] ];We are required to write a JavaScript function that takes in one such array. The function then should pick the smallest subarray (smallest in sense of a number of elements contained) and return it.ExampleThe code for this will be −const arr = [ ["LEFT", "RIGHT", "RIGHT", "BOTTOM", "TOP"], ["RIGHT", "LEFT", "TOP"], ["TOP", "LEFT"] ]; const findShortest = (arr = []) => { const res = arr.reduce((acc, val, ind) => ... Read More

266 Views
Suppose, we have an array of objects like this −const arr = [ { Phase: "Phase 1", Step: "Step 1", Task: "Task 1", Value: "5" }, { Phase: "Phase 1", Step: "Step 1", Task: "Task 2", Value: "10" }, { Phase: "Phase 1", Step: "Step 2", Task: "Task 1", Value: "15" }, { Phase: "Phase 1", Step: "Step 2", Task: "Task 2", Value: "20" }, { Phase: "Phase 2", Step: "Step 1", Task: "Task 1", Value: "25" }, { Phase: "Phase 2", Step: "Step 1", Task: "Task 2", Value: "30" }, { Phase: ... Read More

349 Views
We have got an array of objects. If one property of the object is the same as in another object, we consider it to be a duplicate entry.We want to group objects by this property and store information about how many times the "duplicate" occurred. X A B O Y X Z I Y X Z U X A B L Y X Z KWe want to group by the first value.Another two properties are the same in each duplicate too, but comparing the first value will be enough.We need to display to the user a ... Read More

153 Views
We have a set of vertical regions defined by y1 and y2 coordinates, where y1 is the starting point and y2 is the ending point of each region.The origin of our coordinates system is the top-left corner, so y2 is always greater than y1.This is an example −const regions = [ [10, 100], [50, 120], [60, 180], [140, 220] ];We are required to write a JavaScript function that takes in one such region array as the first argument and a number as the second argument.We would like to find out all disjointed intersections greater than a ... Read More

2K+ Views
Suppose we have two arrays describing some cashflow like these −const months = ["jan", "feb", "mar", "apr"]; const cashflows = [ {'month':'jan', 'value':10}, {'month':'mar', 'value':20} ];We are required to write a JavaScript function that takes in two such arrays. Our function should then construct a combined array of objects that contains an object for each month and the value of cash flow for that month.Therefore, for the above array, the output should look like −const output = [ {'month':'jan', 'value':10}, {'month':'feb', 'value':''}, {'month':'mar', 'value':20}, {'month':'apr', 'value':''} ];ExampleThe code for this will be −const months ... Read More

577 Views
In this article, we will learn to calculate the union of two objects in JavaScript. The union of two objects results in a new object that contains all the properties of both objects. What is the Union of Two Objects? The union of two objects is the process of combining the properties of both objects into a single object. For example Input − const obj1 = { name: " ", email: " " }; const obj2 = { name: ['x'], email: ['y']}; Output − const output = { name: {" ", [x]}, email: {" ", [y]} }; Different Approaches ... Read More

116 Views
Suppose, we have two JavaScript objects defined like this −const a = { a: 1, af: function() { console.log(this.a) }, }; const b = { b: 2, bf: function() { console.log(this.b) }, };We are required to write a JavaScript function that takes in two such objects. Create another object which will get the properties of a and b, like this −const output = { a: 1, af: function() { console.log(this.a) }, b: 2, bf: function() { console.log(this.b) }, }Note that a and b need to stay the same.ExampleThe code for this will ... Read More

280 Views
Let’s say, we have an array of numbers and we added elements to it. You need to devise a simple way to remove a specific element from an array.The following is what we are looking for −array.remove(number);We have to use core JavaScript. Frameworks are not allowed.ExampleThe code for this will be −const arr = [2, 5, 9, 1, 5, 8, 5]; const removeInstances = function(el){ const { length } = this; for(let i = 0; i < this.length; ){ if(el !== this[i]){ i++; continue; ... Read More