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
Finding out the Harshad number JavaScript
Harshad numbers are those numbers which are exactly divisible by the sum of their digits. Like the number 126, it is completely divisible by 1+2+6 = 9. All single digit numbers are harshad numbers. Harshad numbers often exist in consecutive clusters like [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [110, 111, 112], [1010, 1011, 1012]. Our job is to write a function that takes in ...
Read MoreSum of even numbers up to using recursive function in JavaScript
We have to write a recursive function that takes in a number n and returns the sum of all even numbers up to n. A recursive function calls itself with modified parameters until it reaches a base case. For summing even numbers, we'll start from the largest even number ≤ n and work our way down. How It Works The algorithm follows these steps: If the input number is odd, we adjust it to the nearest even number below it Add the current even number to the sum and recursively call with the next smaller ...
Read MoreRemove same values from array containing multiple values JavaScript
In JavaScript, arrays often contain duplicate values that need to be removed. The most efficient modern approach is using Set with the spread operator to create a new array with unique values only. Example Array with Duplicates Let's start with an array containing duplicate student names: const listOfStudentName = ['John', 'Mike', 'John', 'Bob', 'Mike', 'Sam', 'Bob', 'John']; console.log("Original array:", listOfStudentName); Original array: [ 'John', 'Mike', 'John', 'Bob', 'Mike', 'Sam', 'Bob', 'John' ] Using Set with Spread Operator (Recommended) The Set object automatically removes duplicates, and the spread operator converts it ...
Read MoreHow to perform numeric sort in JavaScript?
In JavaScript, the sort() method can be used to sort numeric arrays, but it requires a compare function for proper numeric ordering. Without it, numbers are sorted as strings, leading to unexpected results. The Problem with Default sort() When using sort() without a compare function, JavaScript converts numbers to strings and compares them lexicographically (alphabetically). This causes "10" to come before "2" because "1" comes before "2" in string comparison. let my_array = [61, 34, 54, 2, 12, 67, 89, ...
Read MoreDifference between window.location.href, window.location.replace and window.location.assign in JavaScript?
The window object includes the location object in JavaScript, which provides three different methods for navigating between pages. Each method has distinct behavior regarding browser history and navigation. window.location.href The href property gets or sets the complete URL of the current page. When assigned a new value, it navigates to that URL and adds an entry to the browser's history stack. Example Click below to get the complete URL of the page. Get Current URL ...
Read MoreAndroid 4.0.1 breaks WebView HTML 5 local storage?
Android 4.0.1 introduced stricter security policies that can break HTML5 local storage in WebView components. This issue primarily affects apps targeting older Android versions when loading local HTML content. The Problem For Android versions less than 4.4, loading data into a WebView with a file scheme as a directory won't enable local storage properly: // This approach fails on Android 4.0.1 browser.loadDataWithBaseUrl("file:///android_asset/", html, "text/html", "UTF-8", null); Solution 1: Add Filename to Base URL Adding a specific filename to the base URL resolves the local storage issue on older Android versions: // ...
Read MoreXMLHttpRequest for Video Tag?
XMLHttpRequest can be used to fetch video data as a blob and display it in HTML5 video elements. This approach is useful for loading video content programmatically or handling binary video data. Basic XMLHttpRequest with Blob First, let's understand how to send binary data using XMLHttpRequest with a Blob object: var xhr = new XMLHttpRequest(); xhr.open("POST", "/upload", true); xhr.onload = function (event) { console.log("Upload complete"); }; // Create a blob with text data var blob = new Blob(['demo content'], {type: 'text/plain'}); xhr.send(blob); Loading Video with XMLHttpRequest ...
Read MoreChange the style of bottom border with CSS
The border-bottom-style property changes the style of the bottom border of an element. This CSS property allows you to define how the bottom border line appears visually. Syntax border-bottom-style: none | solid | dashed | dotted | double | groove | ridge | inset | outset; Available Border Styles The border-bottom-style property accepts the following values: solid - A single solid line dashed - A series of short dashes dotted - A series of dots double - Two solid lines groove - A 3D grooved border ridge - A 3D ridged border ...
Read MoreQueue Data Structure in Javascript
In this article, we are going to discuss the queue data structure in JavaScript. It is a linear data structure where the enqueue and dequeue of elements follow the FIFO (first in first out) principle. The queue is open at both ends - one end is used to insert data (enqueue) and the other is used to remove data (dequeue). We use two pointers: rear for insertion and front for removal. A real-world example of the queue can be a single-lane one-way road, where the vehicle that enters first, exits first. Other examples include printer job queues, task scheduling, ...
Read MoreHow to convert a string to JavaScript object?
In JavaScript, you can convert a JSON string to an object using the JSON.parse() method. This is commonly needed when working with API responses or stored data. Syntax JSON.parse(string) Basic Example String to Object Conversion Original JSON String: {"name":"Rohan", "sports":["Cricket", "Football"], "country":"India"} Converted Object Properties: Convert to Object ...
Read More