Articles on Trending Technologies

Technical articles with clear explanations and examples

Checking for majority element in a sorted array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 245 Views

A majority element in an array of length l is an element that appears more than l/2 times. In a sorted array, if a majority element exists, it must occupy the middle position since it spans over more than half the array. Problem Definition We need to write a JavaScript function isMajority() that takes a sorted array and a number, returning true if that number is the majority element, false otherwise. Key Insight for Sorted Arrays In a sorted array, if there exists a majority element, it will always be the middle element. This is because ...

Read More

Separating data type from array into groups in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 649 Views

In JavaScript, you often need to group array elements by their data types. This is useful for data analysis, validation, or organizing mixed-type arrays. We'll create a function that separates elements into groups based on their typeof result. Problem We need to write a JavaScript function that takes an array of mixed data types and returns an object where each key represents a data type and its value is an array containing all elements of that type. Solution Here's how to group array elements by their data types: const arr = [1, 'a', [], ...

Read More

Finding the longest consecutive appearance of a character in another string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 284 Views

Problem We are required to write a JavaScript function that takes in a string as the first argument and a single character as the second argument. Our function should count and return the longest consecutive appearance of the character in the string. Approach We'll iterate through the string and track the current consecutive count and maximum count found so far. When we encounter the target character, we increment the counter. When we encounter a different character, we reset the counter. Example Following is the code − const str = 'abcdaaadse'; const char ...

Read More

crypto.randomBytes() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 4K+ Views

The crypto.randomBytes() method generates cryptographically strong pseudo-random data in Node.js. This method ensures sufficient entropy before completion, typically taking only a few milliseconds to generate secure random bytes. Syntax crypto.randomBytes(size, [callback]) Parameters The parameters are described below: size – Specifies the number of bytes to generate. Must not exceed 2**31 - 1. callback – Optional callback function called if an error occurs. If omitted, the method runs synchronously. Asynchronous Example ...

Read More

What is the SectionList component and how to use it in React Native?

Shilpa S
Shilpa S
Updated on 15-Mar-2026 1K+ Views

The SectionList component in React Native provides an efficient way to display data organized in sections with headers. It's perfect for categorized lists like contacts, settings, or grouped items. Key Features Header/Footer support for the entire list Header/Footer support for individual sections Scroll loading and pull-to-refresh functionality Cross-platform compatibility Sticky section headers Basic Syntax import { SectionList } from "react-native"; Important Props ...

Read More

How to add dashes to the border of a selection area on a canvas using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 535 Views

In this article, we are going to learn how to add dashes to the border of a selection area on a canvas using FabricJS. We can achieve this by using the selectionDashArray property. It allows us to make the border of a selection area dashed. Syntax new fabric.Canvas(element: HTMLElement|String, { selectionDashArray: Array }: Object) Parameters element − This parameter is the element itself which can be derived using document.getElementById() or the id of the element itself. The FabricJS canvas will be ...

Read More

How to set the style of controlling corners of a Rectangle using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 288 Views

In this tutorial, we are going to learn how to set the style of controlling corners of a Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. The controlling corners of an object allow us to scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific colour to it, changing its size etc. We can change the style by using ...

Read More

How to call promise inside another promise in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 5K+ Views

When working with JavaScript, you may find yourself needing to call a promise inside another promise. While this may seem like a daunting task, it is actually quite simple once you understand the basics of promises. In this article, we will discuss how to call a promise inside another promise in JavaScript. The Basics of Promises In order to understand how to call a promise inside another promise, it is important first to understand the basics of promises. A promise is an object that represents the eventual result of an asynchronous operation. Promises are used in JavaScript to ...

Read More

Is it possible to change the value of the function parameter in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 5K+ Views

In this article we are going to find out whether it is possible to change the value of the function parameter in JavaScript. A function accepts certain values as parameters and later while calling this function we need to pass values for these parameters as arguments. Typically a function definition contains the name of the function, parameters (optional) and the body of the function. Syntax Following is the syntax for function parameters − function functionName(parameter1, parameter2, parameter3) { // Statements } Yes, it is possible to change the value of ...

Read More

Search a complex object by id property in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 490 Views

Suppose we have a complex JSON Object like this − const obj = { "id": "0001", "fieldName": "sample1", "fieldValue": "0001", "subList": [ { "id": 1001, "fieldName": "Sample Child 1", "fieldValue": "1001", "subList": [] }, { "id": 1002, "fieldName": "Sample Child 2", ...

Read More
Showing 15771–15780 of 61,297 articles
Advertisements