
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 8591 Articles for Front End Technology

2K+ Views
We will be given an array of numbers / strings that contains some duplicate entries, all we have to do is to return the frequency of each element in the array.Returning an object with an element as key and its value as frequency would be perfect for this situation.We will iterate over the array with a forEach() loop and keep increasing the count of elements in the object if it already exists otherwise we will create a new property for that element in the object.And lastly, we will return the object.The full code for this problem will be −const arr ... Read More

1K+ Views
We are required to write a function breakString() that takes in two arguments first the string to be broken and second is a number that represents the threshold count of characters after reaching which we have to repeatedly add line breaks in place of spaces.So, let’s do it. We will iterate over the with a for loop, we will keep a count that how many characters have elapsed with inserting a ‘’ if the count exceeds the limit and we encounter a space we replace it with line break in the new string and reset the count to 0 otherwise ... Read More

851 Views
We have an array that contains some numbers and some strings, we are required to sort the array such that the numbers get sorted and get placed before every string and then the string should be placed sorted alphabetically.For exampleLet’s say this is our array −const arr = [1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9];The output should look like this −[1, 6, 7, 9, 47, 'afv', 'bdf', 'fdf', 'svd']Therefore, let’s write the code for this −const arr = [1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9]; const sorter = (a, b) => { if(typeof a === ... Read More

230 Views
We are required to write a function that takes in a string as one and only argument and returns another string that has all ‘i’ and ‘o’ replaced with ‘1’ and ‘0’ respectively.It’s one of those classic for loop problems where we iterate over the string with its index and construct a new string as we move through.The code for the function will be −const string = 'Hello, is it raining in Amsterdam?'; const validate = (str) => { let validatedString = ''; for(let i = 0; i < str.length; i++){ if(str[i] === 'a'){ ... Read More

426 Views
We are given a main string and a substring, our job is to create a function, let’s say removeString() that takes in these two arguments and returns a version of the main string which is free of the substring.Here, we need to remove the separator from a string, for example −this-is-a-stingLet’s now write the code for this function −const removeString = (string, separator) => { //we split the string and make it free of separator const separatedArray = string.split(separator); //we join the separatedArray with empty string const separatedString = separatedArray.join(""); return separatedString; } const str ... Read More

1K+ Views
We are required to write a function removeStr() that lives on String.prototype object and takes in a string str, a character char and a number n.The function should remove the nth appearance of char from str.Let’s write the code for this −const str = 'aaaaaa'; const subStr = 'a'; const num = 6; removeStr = function(subStr, num){ if(!this.includes(subStr)){ return -1; } let start = 0, end = subStr.length; let occurences = 0; for(; ;end < this.length){ if(this.substring(start, end) === subStr){ occurences++; }; ... Read More

478 Views
We are required to write a JavaScript function that takes in an array of numbers. The function should return a subarray of two adjacent elements from the original array whose sum is the least amongst all adjacent pairs of the array.If the length of the array is less than 2, we should return boolean false.For example, If the input array is −const arr = [41, 44, -12, 13, -23, 1, 5, -4, 2, 2];Here, the sum of pair [-23, 1] is -22 which is the least for any two adjacent elements of the array, so the function should return [-23, ... Read More

155 Views
We are required to write a JavaScript function that takes in an array of numbers of length N such that N is a positive even integer and divides the array into two sub arrays (say, left and right) containing N/2 elements each.The function should do the product of the subarrays and then add both the results thus obtained.For example, If the input array is −const arr = [1, 2, 3, 4, 5, 6]Then the output should be −(1*2*3) + (4*5*6) 6+120 126The code for this will be −const arr = [1, 2, 3, 4, 5, 6] const subArrayProduct = arr ... Read More

1K+ Views
We are required to write a JavaScript function that takes in a number and checks whether it is a Fibonacci number or not (i.e., it falls in Fibonacci series or not).Our function should return true if the number is a Fibonacci number, false otherwise.The code for this will be −const num = 2584; const isFibonacci = num => { if(num === 0 || num === 1){ return true; } let prev = 1; let count = 2; let temp = 0; while(count

176 Views
Suppose, we have a sorted array of literals like this −const arr = [32, 32, 63, 63, 63, 75, 75, 86, 87, 88, 89];We are required to write a JavaScript function that takes in one such array and returns the first unique number in the array.If there is no such number in the array, our function should return false.For this array, the output should be 86.The code for this will be −const arr = [32, 32, 63, 63, 63, 75, 75, 86, 87, 88, 89]; const firstUnique = arr => { let appeared = false; for(let i = ... Read More