- Trending Categories
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 9297 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
We have to create a function that takes in 2 arguments: an integer and an array of integers. First argument denotes the length of array we have to return and the second argument contains the elements that should not be present in our return array. Actually, we need an array of random numbers between 0 to 100 but it should not include any element that’s present in the argument array.Note − No two numbers should be duplicate.Let’s call our function generateRandom(). The code for this would be −Exampleconst absentArray = [44, 65, 5, 34, 87, 42, 8, 76, 21, 33]; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
614 Views
Let’s say, we have the following data about a team arranged in an array of objects, our task is to convert this data into an object with key as role and value as array of player names.Our sample array −const team = [{ role: 'Batsman', player: 'V Kohli' }, { role: 'Wicket Keeper', player: 'KL Rahul' }, { role: 'Batsman', player: 'R Sharma' }, { role: 'Wicket Keeper', player: 'R Pant' }, { role: 'Bowler', player: 'B Kumar' }, { role: 'Bowler', player: 'M Shami' }, ]Let’s define ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
It is a well-known dilemma that when we use includes() inside nested arrays i.e., multidimensional array, it does not work, there exists a Array.prototype.flat() function which flats the array and then searches through but it’s browser support is not very good yet.So our job is to create a includesMultiDimension() function that takes in an array and a string and returns a boolean based on the presence/absence of that string in the array.There exist many solutions to this problem, most of them includes recursion, heavy array function, loops and what not.What we are going to discuss here is by far the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
70 Views
Suppose, we have two arrays both containing three elements each, the corresponding values of red, green, blue color in integer.Our job is to add the corresponding value to form an array for new rgb color and also making sure if any value adds up to more than 255, we that value to 255.Therefore, let’s define a function addColors() that takes in two arguments, both arrays and returns a new array based on the input.The code for this will be −Exampleconst color1 = [45, 125, 216]; const color2 = [89, 180, 78]; const addColors = (color1, color2) => { const newColor = color1.map((val, index) => { return val + color2[index]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
232 Views
Let’s say we are required to write a function that accepts a string and capitalizes the first letter of every word in that string and changes the case of all the remaining letters to lowercase.For example, if the input string is −hello world coding is very interestingThe output should be −Hello World Coding Is Very InterestingLet’s define a function capitaliseTitle() that takes in a string and capitalises the first letter of each word and returns the string −Examplelet str = 'hello world coding is very interesting'; const capitaliseTitle = (str) => { const string = str .toLowerCase() ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
112 Views
We are given an array of integers and told that all the elements appear for an even number of times except a single element. Our job is to find that element in single iteration.Let this be the sample array −[1, 4, 3, 4, 2, 3, 2, 7, 8, 8, 9, 7, 9]Before attempting this problem, we need to understand a little about the bitwise XOR (^) operator.The XOR operator returns TRUE if both the operands are complementary to each other and returns FALSE if both the operands are the same.TRUTH TABLE OF XOR () operator −0 ^ 0 → 0 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
103 Views
We have the following arrays of objects, we need to merge them into one removing the objects that have redundant value for the property name −const first = [{ name: 'Rahul', age: 23 }, { name: 'Ramesh', age: 27 }, { name: 'Vikram', age: 35 }, { name: 'Harsh', age: 34 }, { name: 'Vijay', age: 21 }]; const second = [{ name: 'Vijay', age: 21 }, { name: 'Vikky', age: 20 }, { name: 'Joy', age: 26 }, { name: 'Vijay', ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
91 Views
Let’s say we have a students object containing two properties names and marks. The names is an array of object with each object having two properties name and roll, similarly marks is an array of object with each object having properties mark and roll. Our task is to combine the marks and names properties according to the appropriate roll property of each object.The students object is given here −const students = { marks: [{ roll: 123, mark: 89 }, { roll: 143, mark: 69 }, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
Here is a simple star pattern that we are required to print inside the JavaScript console. Note that it has to be printed inside the console and not in the output or HTML window −* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Here’s the code for doing so in JavaScript −Exampleconst star = "* "; //where length is no of stars in longest streak const length = 6; for(let i = 1; i
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
241 Views
Let’s say we have a code snippet here that produces some startling results. Firstly, we see that the modulo operator is working fine with strings as well (surprisingly). Secondly, concatenation of two strings produces awkward results.We need to explain why JavaScript does so?Here’s the problem code −Exampleconst numStr = '127'; const result = numStr % 5; const firstName = 'Armaan'; const lastName = 'Malik'; const fullName = firstName + + lastName; console.log('modulo result: ', result); console.log('full name: ', fullName);Outputmodulo result: 2 full name: ArmaanNaNBefore jumping into the code, let’s first learn a bit about one of the most fundamental topics ... Read More