
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

227 Views
We are required to write a JavaScript program that adds two numbers represented as strings, without using any conversion library or built-in methods. For example, If the input number strings are '11' and '23', the output should be '34'. In JavaScript, a number is considered a string-represented number when the number is enclosed in single quotes ('number') or double quotes ("number"). For example: '123' or "456". If you use the typeof operator on such values, it will return the type as 'string'. Here are a few input and output scenarios that provide a better understanding of the given problem: Scenario ... Read More

260 Views
Suppose, we have an array of objects like this −const arr = [ { col1: ["a", "b"], col2: ["c", "d"] }, { col1: ["e", "f"], col2: ["g", "h"] } ];We are required to write a JavaScript function that takes in one such array and returns the following output.const output = [ { col1: "b", col2: "d" }, { col1: "f", col2: "h" } ];Basically, we want to convert ... Read More

809 Views
We are required to write a JavaScript function that takes in two strings as arguments. The function should then check the two strings for common characters and prepare a new string of those characters.Lastly, the function should return that string.The code for this will be −Exampleconst str1 = "IloveLinux"; const str2 = "weloveNodejs"; const findCommon = (str1 = '', str2 = '') => { const common = Object.create(null); let i, j, part; for (i = 0; i < str1.length - 1; i++) { for (j = i + 1; j

13K+ Views
Suppose we have two arrays of objects like these −const arr1 = [{id:'1', name:'A'}, {id:'2', name:'B'}, {id:'3', name:'C'}, {id:'4', name:'D'}]; const arr2 = [{id:'1', name:'A', state:'healthy'}, {id:'3', name:'C', state:'healthy'}];We are required to write a JavaScript function that takes in two such arrays. Our function should return a new filtered version of the first array (arr1 in this case) that contains only those objects with a name property that are not contained in the second array (arr2 in this case) with the same name property.Therefore, the output, in this case, should look like −const output = [{id:'2', name:'B'}, {id:'4', name:'D'}];ExampleThe code ... Read More

793 Views
Sorting an object in ascending order by the value of a key is a common task in JavaScript. Objects are data structures, which are a collection of key-value pairs. Since objects in JavaScript are unordered collections, sorting them directly is not possible. This article will guide you on how to sort an object in ascending order by the value of a key in JavaScript. Understanding the Concept Suppose we have the following object: const obj = { "sub1": 56, "sub2": 67, "sub3": 98, "sub4": 54, ... Read More

1K+ Views
Suppose, we have an array of objects like this −const arr = [{ name : 'Client 1', total: 900, value: 12000 }, { name : 'Client 2', total: 10, value: 800 }, { name : 'Client 3', total: 5, value : 0 }];We are required to write a JavaScript function that takes in one such array and extracts a separate array for each object property.Therefore, one array for the name property of each object, one for total and one for value. If there existed more properties, we would have separated more ... Read More

461 Views
We are required to illustrate the correct way to check whether a particular key exists in an object or not. Before moving on to the correct way let's first examine an incorrect way and see how actually its incorrect.Way 1: Checking for undefined value (incorrect way)Due to the volatile nature of JavaScript, we might want to check for the existence of key in an object like this −const obj = { name: 'Rahul' };if(!obj['fName']){}orif(obj['fName'] === undefined){}These both are incorrect ways. Why?Because in this case there happens to be no 'fName' key, but suppose there existed a 'fName' which was deliberately ... Read More

139 Views
We are required to write a JavaScript function that takes in an array of numbers. Our function should return true if the difference between all adjacent elements is the same positive number, false otherwise.ExampleThe code for this will be −const arr = [4, 7, 10, 13, 16, 19, 22]; const growingMarginally = arr => { if(arr.length

153 Views
const sort = ["this", "is", "my", "custom", "order"]; const myObjects = [ {"id":1, "content":"is"}, {"id":2, "content":"my"}, {"id":3, "content":"this"}, {"id":4, "content":"custom"}, {"id":5, "content":"order"} ];We are required to write a JavaScript function that takes in two such arrays and sorts the second array of objects on the basis of the first array so that the content property of objects are matched with the strings of the first array.Therefore, for the above arrays the output should look like −const output = [ {"id":3, "content":"this"}, {"id":1, "content":"is"}, {"id":2, "content":"my"}, {"id":4, "content":"custom"}, {"id":5, "content":"order"} ];ExampleThe ... Read More

392 Views
We are required to write a JavaScript function that takes in an array of Numbers. The array may contain more than one greatest element (i.e., repeating greatest element).We are required to write a JavaScript function that takes in one such array and returns all the indices of the greatest element.ExampleThe code for this will be −const arr = [10, 5, 4, 10, 5, 10, 6]; const findGreatestIndices = arr => { const val = Math.max(...arr); const greatest = arr.reduce((indexes, element, index) => { if(element === val){ return indexes.concat([index]); } else { return indexes; }; }, []); return greatest; } console.log(findGreatestIndices(arr));OutputAnd the output in the console will be −[ 0, 3, 5 ]