
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

1K+ Views
In JavaScript, there are scenarios where you may need to generate every possible combination of a string's characters. This can be especially useful in areas like cryptography, analyzing subsets of data, or solving problems involving permutations. In this article, we’ll learn to implement a JavaScript function to achieve this task. Generate all combinations of supplied words Following are the different approaches for generating all combinations of supplied words − Recursive Approach Iterative Approach Using Bitmasking Using Recursive Approach The function iterates over each character in the string, appending ... Read More

218 Views
Consider the following backtracing problem: On a 2−dimensional grid, there are 4 types of squares −1 represents the starting square. There is exactly one starting square.2 represents the ending square. There is exactly one ending square.0 represents empty squares we can walk over.−1 represents obstacles that we cannot walk over.We are required to write a function that returns the number of 4−directional walks from the starting square to the ending square, that walk over every non−obstacle square exactly once.Exampleconst arr = [ [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 2, -1] ]; const uniquePaths ... Read More

327 Views
We are required to write a function that does the following −takes an array of integers as an argument (e.g. [1, 2, 3, 4])creates an array of all the possible permutations of [1, 2, 3, 4], with each permutation having a length of 4 (i.e., the length of original array)ExampleThe code for this will be −const arr = [1, 2, 3, 4]; const permute = (arr = [], res = [], used = []) => { let i, ch; for (i = 0; i < arr.length; i++) { ch = arr.splice(i, 1)[0]; ... Read More

663 Views
Suppose, we have an array of objects containing data about likes of some users like this −const arr = [ {"user":"dan", "liked":"yes", "age":"22"}, {"user":"sarah", "liked":"no", "age":"21"}, {"user":"john", "liked":"yes", "age":"23"}, ];We are required to write a JavaScript function that takes in one such array. The function should construct another array based on this array like this −const output = [ {"dan":"yes"}, {"sarah":"no"}, {"john":"yes"}, ];Exampleconst arr = [ {"user":"dan", "liked":"yes", "age":"22"}, {"user":"sarah", "liked":"no", "age":"21"}, {"user":"john", "liked":"yes", "age":"23"}, ]; const mapToPair = (arr = []) => { const result = arr.map(obj => ... Read More

173 Views
We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a target sum Number as the second argument.The function should return an array of all those subarrays from the original array whose elements sum to make the target sum. We can use a single number twice to achieve the sum.For example −If the input array and number are −const arr = [1, 2, 4]; const sum = 4;then the output should be −const output = [ [1, 1, 1, 1], [1, 1, 2], [2, 2], [4] ... Read More

456 Views
Suppose, we have an array of objects like this −const arr = [ {"id":7, "name":"Kuwait", "parentId":2}, {"id":4, "name":"Iraq", "parentId":2}, {"id":10, "name":"Qatar", "parentId":2}, {"id":2, "name":"Middle East", "parentId":1}, {"id":3, "name":"Bahrain", "parentId":2}, {"id":6, "name":"Jordan", "parentId":2}, {"id":8, "name":"Lebanon", "parentId":2}, {"id":1, "name":"Africa/Middle East", "parentId":null}, {"id":5, "name":"Israel", "parentId":2}, {"id":9, "name":"Oman", "parentId":2} ];We are required to write a JavaScript function that takes in one such array. The function should then prepare a new array that contains the objects grouped according to their parents.Therefore, the output should look like this −const output = [ ... Read More

339 Views
Suppose, we have two arrays, let’s say arr1 and arr2. The elements of arr2 are distinct, and all elements in arr2 are also in arr1.We are required to write a JavaScript function that takes in two such arrays and sorts the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order.For example− If the two input arrays are −const arr1 = [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19]; const arr2 = ... Read More

283 Views
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.The function should then return the length of the longest continuous subarray from the array that only contains elements in a strictly increasing order.A strictly increasing sequence is the one in which any succeeding element is greater than all its preceding elements.Exampleconst arr = [5, 7, 8, 12, 4, 56, 6, 54, 89]; const findLongest = (arr) => { if(arr.length == 0) { return 0; }; let max = 0; let count ... Read More

560 Views
The degree of an array of literals is defined as the maximum frequency of any one of its elements.const arr = [1, 2, 3, 3, 5, 6, 4, 3, 8, 3];The degree of this array is 4, because 3 is repeated 4 times in this array.We are required to write a JavaScript function that takes in an array of literals. The task of our function is to find the length of the smallest continious subarray from the array whose degree is same as of the whole array.Exampleconst arr = [1, 2, 3, 3, 5, 6, 4, 3, 8, 3]; const ... Read More

1K+ Views
In this article, we will learn to create an array from JSON data in JavaScript. JSON is a widely used format for storing and exchanging data. A common use case involves extracting specific data from a JSON object or array and converting it into a separate array for further processing. What is JSON Data? JSON (JavaScript Object Notation) is a lightweight data format commonly used to store and exchange data between a server and a client. It represents data as key-value pairs and is easy for both humans and machines to read and write. In JavaScript, JSON objects or arrays can be ... Read More