![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 9326 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
315 Views
Suppose, we have an object like this −const obj = {"100":"Jaipur", "101":"Delhi", "102":"Raipur", "104":"Goa"};We are required to write a JavaScript function that takes in one such object as the first argument and a search query term as the second argument. Then our function should return all those key/value pairs whose value includes the search term provided to the function as the second argument.We will simply iterate through the object, building the resulting object (if it matches the condition) as we move through and lastly return that object.ExampleThe code for this will be −const obj = { "100":"Jaipur", "101":"Delhi", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
172 Views
We are required to write a JavaScript function that takes in any number of array of Numbers. Our function should return an array of greatest numbers picked from the input array of array. The number of elements in the output array should be equal to the number of subarrays contained in the original input array.ExampleThe code for this will be −const arr1 = [117, 121, 18, 24]; const arr2 = [132, 19, 432, 23]; const arr3 = [32, 23, 137, 145]; const arr4 = [900, 332, 23, 19]; const mergeGreatest = (...arrs) => { const res = []; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
We are required to write a JavaScript function that takes in a stringified mathematical equation. The function should return the result of the equation provided to the function.For example: If the equation is −const str = '1+23+4+5-30';Then the output should be 3ExampleThe code for this will be −const str = '1+23+4+5-30'; const compute = (str = '') => { let total = 0; str = str.match(/[+\−]*(\.\d+|\d+(\.\d+)?)/g) || []; while (str.length) { total += parseFloat(str.shift()); }; return total; }; console.log(compute(str));OutputAnd the output in the console will be −3
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
149 Views
We have an array that contains many objects. We are required to write a function to sort the first half of the array in ascending order.And the second half of the array with ascending order to but without inter mixing the entries of halves into one another.Consider this sample array −const arr = [ {id:1, x: 33}, {id:2, x: 22}, {id:3, x: 11}, {id:4, x: 3}, {id:5, x: 2}, {id:6, x: 1} ];Our function should sort this array on the basis of the 'x' property of the objects keeping the things mentioned above in ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
Suppose, we have an object like this −const obj = { "value 0": "value", "value 1": "value", "value 2": "value", "value 3": "value", "value 4": "value", "value 5": "value", "value 6": "value", "value 7": "value", "value 8": "value", "value 9": "value" };We are required to write a JavaScript function that takes in one such object. The function should return a new array of objects in which each key/value pair is separated into its own separate object.ExampleThe code for this will be −const obj = { "value 0": "value", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
78 Views
Suppose, we have an array of objects describing the routes of some flights like this −const routes = [ { flyFrom: "CDG", flyTo: "DUB", return: 0, }, { flyFrom: "DUB", flyTo: "SXF", return: 0, }, { flyFrom: "SFX", flyTo: "CDG", return: 1, } ];We need to count how many times there is return − 0 and how many times there is the return: 1.The end output should ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
We are required to write a JavaScript program that provides user with a input. When the user inputs some value and press the button, our function should check if the input is a valid number, if it is a valid number, the program should print all digits of the number separately to the screen.For example − If the input is −43354Then the output on the screen should be −4 3 3 5 4Let us write the code for this function −The code for this will be −HTML ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Suppose we have two arrays of literals like this −const arr1 = ["A", "B", "C"]; const arr2 = ["1", "2", "3"];We are required to write a JavaScript function that takes in two such arrays of literals. The function should then combine each element of the first array with each element of the second array and push them into a new array.Therefore, the output for the above input should look like this −const output = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];ExampleThe code for this will be −const arr1 = ["A", "B", "C"]; const arr2 = ["1", "2", "3"]; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
106 Views
We have a set of numbers and our requirement is to find the same or the nearest higher number key to a specific number provided as the input to the function.The set of numbers is defined as −const numbers = { A:107, B:112, C:117, D:127, E:132, F:140, G:117, H:127, I:132, J:132, K:140, L:147, M:117, N:127, O:132 };ExampleThe code for this will be −const numbers = { A:107, B:112, C:117, D:127, E:132, F:140, G:117, H:127, I:132, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
664 Views
We are required to write a JavaScript function that generates combinations from n number of arrays with m number of elements in them.For example −Consider this data −const arr = [ [0, 1], [0, 1, 2, 3], [0, 1, 2] ]3 sub arrays, with a different number of elements in them.What we want to do is get all combinations by combining an item from each array.For example −0, 0, 0 // item 0 from array 0, item 0 from array 1, item 0 from array 2 0, 0, 1 0, 0, 2 0, 1, 0 0, 1, ... Read More