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
AmitDiwan has Published 10740 Articles
AmitDiwan
526 Views
Consider, we have the following array of objects −const arr = [{ id: 121, hobby: 'cycling' }, { id: 125, hobby: 'jogging' }, { id: 129, hobby: 'reading' }, { id: 121, hobby: 'writing' }, { id: 121, hobby: 'playing ... Read More
AmitDiwan
802 Views
Happy NumberA happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit. Whereas if during this process any number gets repeated, the cycle will run infinitely and such numbers are called unhappy numbers.For example − 13 is a happy number ... Read More
AmitDiwan
425 Views
Consider the following array of numbers −const arr = [10, 5, 6, 12, 7, 1];The sum of its consecutive elements taking one less element in every go will be −[10, 5, 6, 12, 7, 1] = 10 + 5 + 6 + 12 + 7 + 1 = 41; [5, ... Read More
AmitDiwan
387 Views
Let’s say, we are required to write an array method that overwrites the default Array.prototype.slice(). Usually the Array.prototype.slice() method takes in two arguments the start index and the end index, and returns a subarray of the original array from index start to end-1.What we wish to do is make this ... Read More
AmitDiwan
388 Views
Let’s say, we are required to write a function that takes in an array of string / number literals and returns the index of the item that appears for the most number of times. We will iterate over the array and prepare a frequencyMap and from that map we will ... Read More
AmitDiwan
387 Views
We have to write a function that returns true if a portion of string1 can be rearranged to string2. Write function, say scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.For example −Let’s say string1 is str1 and string2 ... Read More
AmitDiwan
208 Views
Let’s say, we have an array that contains some data about the speed of a motor boat during upstreams and downstreams like this −Following is our sample array −const arr = [{ direction: 'upstream', velocity: 45 }, { direction: 'downstream', velocity: 15 }, { direction: ... Read More
AmitDiwan
209 Views
Let’s say, we are given a string and an array. Our job is to split the string according to the corresponding elements of the array. For example −Inputconst string = 'Javascript splitting string by given array element'; const arr = [2, 4, 5, 1, 3, 1, 2, 3, 7, 2];Output['Ja', ... Read More
AmitDiwan
161 Views
We are required to write a function that returns a random hex color. So here is the code for doing so −Exampleconst generateRandomColor = () => { const keys = '0123456789ABCDEF'; let color = ''; while(color.length < 6){ const random = Math.floor(Math.random() * 16); ... Read More
AmitDiwan
184 Views
We are required to write a function, say sumBetween() that takes in an array [a, b] of two elements and returns the sum of all the elements between a and b including a and b.For example −[4, 7] = 4+5+6+7 = 22 [10, 6] = 10+9+8+7+6 = 40Let’s write the ... Read More