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
Sorting array of exactly three unique repeating elements in JavaScript
Suppose we have an array of Numbers that contains any frequency of exactly three elements: -1, 0 and 1 like this: const arr = [1, 1, 0, -1, 1, 0, -1, 1, 0, 0, 1]; console.log("Original array:", arr); Original array: [ 1, 1, 0, -1, 1, 0, -1, 1, 0, 0, 1 ] We are required to write a JavaScript function that takes in one such array. The function should simply sort this special array in place (without using any extra array to store the values). The only condition is that our function ...
Read MoreChecking for squared similarly of arrays in JavaScript
We are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and second argument respectively. Our function should return true if and only if every element in arr2 is the square of any element of arr1 irrespective of their order of appearance. For example, if the input to the function is: Input const arr1 = [4, 1, 8, 5, 9]; const arr2 = [81, 1, 25, 16, 64]; Output const output = true; Using Frequency Map Approach The ...
Read MoreHow to make an Ellipse invisible using FabricJS?
In this tutorial, we are going to learn how to make an Ellipse invisible using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will create an instance of fabric.Ellipse class and add it to the canvas. Our ellipse object can be customized in various ways like changing its dimensions, adding a background color or by making it visible or invisible. We can do this by using the visible property. Syntax new fabric.Ellipse( { visible: Boolean }: Object) Parameters ...
Read MoreHow to create an element from a string in JavaScript?
In this tutorial, we will explore various methods to create HTML elements from strings in JavaScript. Creating elements dynamically from strings is essential for building interactive websites, such as to-do list apps where items are added, deleted, and edited on the fly. Using createElement() Method The createElement() method is the standard way to create HTML elements dynamically in JavaScript. This method takes a string parameter representing the tag name and returns a new HTML element. Syntax document.createElement(tagName) Where tagName is a string representing the HTML tag (like "div", "p", "h1", "img"). The method ...
Read MoreMapping string to Numerals in JavaScript
We are required to write a JavaScript function that takes in a string. It should print out each number for every corresponding letter in the string. Letter to Number Mapping Each letter corresponds to its position in the alphabet: a = 1 b = 2 c = 3 d = 4 e = 5 ... y = 25 z = 26 Note: The function should remove any special characters and spaces, processing only alphabetic characters. Example Input and Output If the input is: "hello man" Then the output ...
Read MoreGenerating all possible permutations of array in JavaScript
In JavaScript, generating all possible permutations of an array involves creating every unique arrangement of its elements. This is a common algorithmic problem that can be solved using recursion and array manipulation methods. What is Array Permutation? Array permutation refers to different arrangements of elements within an array. For an array with n elements, there are n! (factorial) possible permutations. Each permutation represents a unique ordering of the same elements. // Input array const arr = [1, 2, 3]; // All possible permutations ...
Read MoreInserting a new interval in a sorted array of intervals in JavaScript
For the purpose of this question, we define an interval as an array of two numbers where the first number is always smaller than the second number. For example − [4, 6], [2, 3], [6, 8], [2, 7], [1, 8] are all examples of valid intervals. Suppose, we have an array of intervals which is sorted according to their start times (the first elements of each interval). The intervals in the array are non-overlapping which means that for any two arbitrary adjacent intervals: [m, n], [x, y] m < n < x ...
Read MoreValidating alternating vowels and consonants in JavaScript
Validating alternating vowels and consonants is a common string pattern validation problem. We need to check if vowels (a, e, i, o, u) and consonants alternate throughout the string. Problem Statement Write a JavaScript function that takes a string of English alphabets and returns true if vowels and consonants appear alternatingly, false otherwise. For example: Input: 'amazon' Output: true Explanation: a(vowel) → m(consonant) → a(vowel) → z(consonant) → o(vowel) → n(consonant) Solution const str = 'amazon'; const appearAlternatingly = (str = '') => { if (str.length === 0) ...
Read MoreHow to make the controlling corners of an Ellipse transparent using FabricJS?
In this tutorial, we are going to learn how to make the controlling corners of Ellipse transparent using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will create an instance of fabric.Ellipse class and add it to the canvas. The transparentCorners property allows us to make the controlling corners of Ellipse transparent. Syntax new fabric.Ellipse({ transparentCorners: Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to ...
Read MoreHow to check if the value is primitive or not in JavaScript?
In JavaScript, data types are divided into two categories: primitive and non-primitive. Understanding how to check if a value is primitive is crucial for proper data handling. Primitive data types: String, number, undefined, boolean, null, symbol, and bigint. Non-primitive data types: Objects (including arrays, functions, and dates). Primitive values are immutable and represent data at the lowest level of the language. When you "change" a primitive value, you're actually creating a new value and reassigning it to the variable. Using Object() Constructor The Object() constructor converts primitive values to objects. By comparing the original value with ...
Read More