
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

644 Views
Suppose, we have an array of objects like this −const arr = [ { assigned_user:{ name:'Paul', id: 34158 }, doc_status: "processed" }, { assigned_user:{ name:'Simon', id: 48569 }, doc_status: "processed" }, { assigned_user:{ name:'Simon', id: 48569 }, doc_status: "processed" } ];We are required ... Read More

479 Views
We are required to write a JavaScript program that provides the user an input to enter a string value.The program should then check the input value against some hard-coded array values. Our program should print true to the screen if the input string value is included in the array, false otherwise.ExampleThe code for this will be − CHECK EXISTENCE const arr = ['arsenal', 'chelsea', 'everton', 'fulham', 'swansea']; const checkExistence = () => { const userInput = document.getElementById("input").value; const exists = arr.includes(userInput); document.getElementById('result').innerText = exists; }; Check OutputAnd the output on the screen will be −

210 Views
Suppose, we have an array of strings that contains some duplicate entries like this −const arr = ['blue', 'blue', 'green', 'blue', 'yellow', 'yellow', 'green'];We are required to write a JavaScript function that takes in one such array. The function should merge all the duplicate entries with one another.Therefore, the output for the above input should look like this −const output = ['blueblue', 'green', 'blue', 'yellowyellow', 'green'];ExampleThe code for this will be −const arr = ['blue', 'blue', 'green', 'blue', 'yellow', 'yellow', 'green']; const combineDuplicate = (arr = []) => { let prev = null; const groups = arr.reduce((acc, value) ... Read More

911 Views
Suppose, we have an array of objects like this −const arr = [{ name: 'Paul', country: 'Canada', }, { name: 'Lea', country: 'Italy', }, { name: 'John', country: 'Italy', }, ];We are required to devise a way to filter an array of objects depending on a string keyword. The search has to be made in any properties of the object.For instance −When we type "lea", we want to go through all the objects and all their properties to return the objects that contain "lea". When we type "italy", we want to go through all ... Read More

600 Views
Suppose, we have an array of objects like this −const arr = [ {id:123, value:"value1", name:"Name1"}, {id:124, value:"value2", name:"Name1"}, {id:125, value:"value3", name:"Name2"}, {id:126, value:"value4", name:"Name2"} ];Note that some of the "name" property in objects within the array are duplicate.We are required to write a JavaScript function that takes in one such array of objects. The function should then construct a new array of strings that contains only unique "name" property value from the array.Therefore, the output for the above input should look like this −const output = ["Name1", "Name2"];ExampleThe code for this will be −const arr ... Read More

1K+ Views
Suppose, we have an array of objects containing data about some cars like this −const arr = [ { 'make': 'audi', 'model': 'r8', 'year': '2012' }, { 'make': 'audi', 'model': 'rs5', 'year': '2013' }, { 'make': 'ford', 'model': 'mustang', 'year': '2012' }, { 'make': 'ford', 'model': 'fusion', 'year': '2015' }, { 'make': 'kia', ... Read More

702 Views
We are required to write a JavaScript function that takes in three argument, namely:day, month and year. Based on these three inputs, our function should find the day of the week on that date.For example: If the inputs are −day = 15, month = 8, year = 1993OutputThen the output should be −const output = 'Sunday'ExampleThe code for this will be −const dayOfTheWeek = (day, month, year) => { // JS months start at 0 return dayOfTheWeekJS(day, month - 1, year); } function dayOfTheWeekJS(day, month, year) { const DAYS = [ 'Sunday', ... Read More

531 Views
The power of the string is the maximum length of a non−empty substring that contains only one unique character.We are required to write a JavaScript function that takes in a string and returns its power.For example −const str = "abbcccddddeeeeedcba"Then the output should be 5, because the substring "eeeee" is of length 5 with the character 'e' only.ExampleThe code for this will be −const str = "abbcccddddeeeeedcba" const maxPower = (str = '') => { let power = 1 const sz = str.length - 1 for(let i = 0; i < sz; ++i) { ... Read More

482 Views
We are required to write a JavaScript function that takes in an array of arrays. Each subarray will contain exactly two items, representing the x and y coordinates respectively.Our function should check whether or not the coordinates specified by these subarrays form a straight line.For example −[[4, 5], [5, 6]] should return true.The array is guaranteed to contain at least two subarrays.ExampleThe code for this will be −const coordinates = [ [4, 5], [5, 6] ]; const checkStraightLine = (coordinates = []) => { if(coordinates.length === 0) return false; let x1 = coordinates[0][0]; let y1 = coordinates[0][1]; let slope1 = null; for(let i=1;i

732 Views
Like the base−2 representation (binary), where we repeatedly divide the base 10 (decimal) numbers by 2, in the base 7 system we will repeatedly divide the number by 7 to find the binary representation.We are required to write a JavaScript function that takes in any number and finds its base 7 representation.For example −base7(100) = 202ExampleThe code for this will be −const num = 100; const base7 = (num = 0) => { let sign = num < 0 && '−' || ''; num = num * (sign + 1); let result = ''; while (num) { result = num % 7 + result; num = num / 7 ^ 0; }; return sign + result || "0"; }; console.log(base7(num));OutputAnd the output in the console will be −202