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
Indexing numbers to alphabets in JavaScript
We are required to write a JavaScript function that takes in a number between the range [0, 25], both inclusive and returns the corresponding alphabet character. Return Value The function should return the corresponding alphabet for that number, where 0 = 'A', 1 = 'B', 2 = 'C', and so on. Using String.fromCharCode() Method The most common approach uses ASCII values. The ASCII value of 'A' is 65, so we add our number to get the corresponding character. const num = 15; const indexToAlpha = (num = 1) => { ...
Read MoreFinding next greater node for each node in JavaScript
We are required to write a JavaScript function that takes in the head of a linked list as the first and only argument. This linked list contains numerical data. Each node in the list may have a next larger value: for node_i, next_larger(node_i) is the node_j.val such that j > i, node_j.val > node_i.val, and j is the smallest possible choice. If such a j does not exist, the next larger value is 0. Our function should prepare and return an array in which the corresponding element is the next greater element for the element in the list. ...
Read MoreChecking for vowels in array of numbers using JavaScript
We are required to write a JavaScript function that takes in an array of numbers. If in that array there exists any number which is the char code of any vowel in ASCII, we should switch that number to the corresponding vowel and return the new array. Understanding ASCII Character Codes In ASCII, vowels have specific character codes: 'a' = 97 'e' = 101 'i' = 105 'o' = 111 'u' = 117 Example Let's create a function that converts ASCII codes to vowels when they match: const arr = [5, 23, ...
Read MoreHow to pause and play a loop using event listeners in JavaScript?
In this article, we'll learn how to pause and resume a JavaScript loop using event listeners and promises. This technique is useful for creating controllable animations, counters, or any iterative process that needs user interaction. An event listener attaches an event handler to an element, allowing us to respond to user interactions like button clicks. Syntax element.addEventListener(event, function, useCapture); Parameters event − The name of the event (e.g., "click") function − The function to execute when the event occurs useCapture ...
Read MoreGame Development Using JavaScript
In this tutorial, we will learn about whether we can create games using JavaScript or not. We can, of course. JavaScript games are entertaining, simple, and a fantastic method for youngsters to learn how to code. Nearly all internet websites employ the popular programming language known as JavaScript. A web application can be enhanced using JavaScript by adding animations and interactivity that improve gaming and web browsing. JavaScript's capacity to create games that can be played readily online is a common topic that draws young people to learn how to program. It makes sense that more game developers ...
Read MoreHow do I console.log JavaScript variables as it relates to DOM?
To display variables on console when working with the DOM, you can use console.log() to output element objects, their properties, or values. The document.getElementById() method retrieves DOM elements which can then be logged to examine their properties. Logging DOM Elements When you log a DOM element directly, the browser console displays the element object with all its properties: Console Log DOM Example Hello World ...
Read MoreASCII sum difference of strings in JavaScript
ASCII (American Standard Code for Information Interchange) is a 7-bit character encoding standard where every character has a unique decimal code. We can calculate the ASCII sum of strings and find their difference in JavaScript. Understanding ASCII Codes Each character has a specific ASCII value. For example, 'A' = 65, 'a' = 97, '0' = 48, and space = 32. We can get these values using JavaScript's charCodeAt() method. Getting ASCII Values console.log('A'.charCodeAt(0)); // 65 console.log('a'.charCodeAt(0)); // 97 console.log('0'.charCodeAt(0)); // 48 console.log(' '.charCodeAt(0)); ...
Read MoreWhat's the most efficient way to turn all the keys of an object to lower case - JavaScript?
When working with JavaScript objects, you may need to convert all property keys to lowercase for consistency. Here's how to efficiently transform object keys using built-in JavaScript methods. Sample Object Let's start with an object that has uppercase keys: var details = { "STUDENTNAME": "John", "STUDENTAGE": 21, "STUDENTCOUNTRYNAME": "US" }; console.log("Original object:", details); Original object: { STUDENTNAME: 'John', STUDENTAGE: 21, STUDENTCOUNTRYNAME: 'US' } Method 1: Using Object.keys() and while Loop This approach uses a while loop to iterate ...
Read MoreExpressive words problem case in JavaScript
Sometimes people repeat letters to represent extra feeling, such as "hello" → "heeellooo", "hi" → "hiiii". In these strings like "heeellooo", we have groups of adjacent letters that are all the same: "h", "eee", "ll", "ooo". For some given string S, a query word is stretchy if it can be made to be equal to S by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is 3 or more. For example, starting with ...
Read MoreFinding the smallest positive integer not present in an array in JavaScript
We are required to write a JavaScript function that takes in array of integers as the first and the only argument. Our function should find and return that smallest positive integer which is not present in the array. For example, if the input array is: const arr = [4, 2, -1, 0, 3, 9, 1, -5]; Then the output should be: 5 Because 1, 2, 3, 4 are already present in the array and 5 is the smallest positive integer absent from the array. Using Sequential Search Approach ...
Read More