Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Smallest number formed by shuffling one digit at most in JavaScript
We need to write a JavaScript function that takes a positive number and can perform at most one operation: remove a digit from any position and insert it at another position to create the smallest possible number. Problem Statement Given a positive number, we can choose any digit, remove it from its current position, and insert it at any other position (including the same position). The goal is to find the smallest number possible with this single operation. Algorithm Approach The strategy is to find the smallest digit in the number and move it to the ...
Read MoreLimiting elements occurrences to n times in JavaScript
Problem We are required to write a JavaScript function that takes in an array of integers, arr, that may contain duplicates as the first argument, and a number, num, as the second and final argument. The task of our function is to iterate through the array and check whether there exists some number that appears for more than n times in the array. If there exists any such element, we should delete its extra occurrences to limit its occurrence to at most num. For example, if the input to the function is: Input ...
Read MoreHow to create an Ellipse with not-allowed cursor on hover over objects using FabricJS?
In this tutorial, we are going to create an Ellipse with a not-allowed cursor on hover over objects using FabricJS. not-allowed is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize etc which are reusing the native cursor underhood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Ellipse({ hoverCursor: String }: Object) Parameters options (optional) ...
Read MoreHow to create a Textbox with crosshair cursor on moving objects using FabricJS?
In this tutorial, we are going to create a Textbox with a crosshair cursor on moving objects using FabricJS. Crosshair is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., which are reusing the native cursor underhood. The moveCursor property sets the style of the cursor when the object is moved around in the canvas. Syntax new fabric.Textbox(text: String, { moveCursor: String }: Object) Parameters ...
Read MoreHow to find every element that exists in any of two given arrays once using JavaScript?
In this tutorial, we will learn how to find every element that exists in any of two given arrays once. This means creating a new array containing all unique elements from both arrays, with no duplicates. For example, given two arrays: Input const arr1 = [1, 2, 3, 4, 5] const arr2 = [1, 4, 9, 16, 25] Output result = [1, 2, 3, 4, 5, 9, 16, 25] Input const arr1 = ['Deepansh', 'Aditya', 'Rishabh', 'Rishit'] const arr2 = ['Vikrant', 'Rishabh', 'Mohit', 'Rishit'] Output result = ['Deepansh', ...
Read MoreHow to Check Mentioned File Exists or not using JavaScript/jQuery?
Using JavaScript or jQuery, we can check whether a file exists and retrieve metadata about the file, such as its size, content type, last modified date, etc., without retrieving the actual file. The HTTP HEAD request is used in this case. An HTTP HEAD request is a type of HTTP request that asks the server to return the HTTP headers for a specified resource without the actual resource itself. Several methods can be used to send an HTTP HEAD request, but the most popular way is to use the $.ajax() method and XMLHttpRequest object. Users can define the request ...
Read MorePushing false objects to bottom in JavaScript
Suppose we have an array of objects like this − const array = [ {key: 'a', value: false}, {key: 'a', value: 100}, {key: 'a', value: null}, {key: 'a', value: 23} ]; We are required to write a JavaScript function that takes in one such array and places all the objects that have falsy values for the "value" property to the bottom and sorts all other objects in decreasing order by the "value" property. Understanding Falsy Values In JavaScript, falsy values include: false, ...
Read MoreMultiply and Sum Two Arrays in JavaScript
We are required to write a JavaScript function that takes in two arrays of equal length. The function should multiply the corresponding (by index) values in each, and sum the results. For example: If the input arrays are − const arr1 = [2, 3, 4, 5]; const arr2 = [4, 3, 3, 1]; then the output should be 34, because: (2*4 + 3*3 + 4*3 + 5*1) = 8 + 9 + 12 + 5 = 34 Using for Loop The most straightforward approach uses a for loop to iterate ...
Read MoreCalculating the sum of digits of factorial JavaScript
We are required to write a JavaScript function that takes in a number. The function should first calculate the factorial of that number and then it should return the sum of the digits of the calculated factorial. For example, for the number 6, the factorial will be 720, so the sum of digits (7 + 2 + 0) should be 9. Understanding the Problem This problem involves two steps: Calculate the factorial of a given number Sum all digits in the factorial result Step 1: Calculate ...
Read MoreFinding the first non-repeating character of a string in JavaScript
We are required to write a JavaScript function that takes in a string as the first and the only argument. The function should find and return the index of first character it encounters in the string which appears only once in the string. If the string does not contain any unique character, the function should return -1. For example, if the input string is: const str = 'hellohe'; Then the output should be: const output = 4; Because the character 'o' at index 4 is the first character that ...
Read More