Convert Negative Number to Positive in JavaScript

Shubham Vora
Updated on 10-Aug-2022 11:56:39

13K+ Views

This tutorial will teach us to convert negative numbers to positive ones. Sometimes, programmers need to perform some operation with the unsigned value of the number, and in such a case, they need to convert the negative numbers to positive numbers. We will go through the various methods to convert a negative number to a positive number in this tutorial. Using the Math.abs() Method Multiplying the negative number with -1 Using the Bitwise Not Operator Using the Math.abs() Method The Math.abs() method is the JavaScript math library method. The Math.abs() method takes a value as a parameter and ... Read More

Replace Each Node in Binary Tree with Sum of Inorder Predecessor and Successor Using C++

Prateek Jangid
Updated on 10-Aug-2022 11:54:27

365 Views

We are given a binary tree, and we need to replace all the elements with the sum of its inorder predecessor and successor. Inorder is a traversed path in a graph that reads in the order of left node – root node – right node. The method adds the elements in left and right nodes of the parent node and replaces the value with the obtained sum. Suppose we have a tree with the following formation and characters − We can find and store the inorder of the tree in an array. After that, we can again do an ... Read More

Convert Decimal to Binary in JavaScript

Shubham Vora
Updated on 10-Aug-2022 11:51:59

21K+ Views

This tutorial will teach us to convert the decimal number to a binary number string. The binary number is the string of only 0 and 1. The computer doesn’t understand the high-level programming language, so we need to instruct the computer in a low-level language, represented as the binary string. Also, binary string is used in digital electronics. Here, we have three methods to convert the decimal number to a binary string. Using the toString() Method Using the right shift Operation Using the modulo Operator Using the toString() Method The toString() method is JavaScript built-in string method that ... Read More

Rencontres Number Counting Partial Derangements Using C++

Prateek Jangid
Updated on 10-Aug-2022 11:50:50

314 Views

Given two integers N and k, we need to count the number of derangements where k points are fixed at their position. Given constraints on k are between 0 and n as the number of fixed points when there are n points cannot be more than n. int N=4, k=2; res = solve(N, k); Note that at least conditions don’t hold on k. There has to be precisely and strictly k points on their original index. This is a mathematical problem. Not explaining the proof and explanation of mathematics, we as computer science majors can use the results ... Read More

Remove Edges to Separate Nodes into Different Trees Using C++

Prateek Jangid
Updated on 10-Aug-2022 11:48:01

206 Views

Suppose we are given a binary tree and three nodes in that binary. We have to disconnect one node entirely from the tree. Disconnecting that node leaves us with three different trees. Each of the three given nodes lies in one of them, or each of the given three nodes must not exist in the same tree. Disconnecting a node means that we will remove all the edges from this node to all other nodes. Example For example, let's say we have a tree with three nodes 18, 15, and 17 as shown below − If the task ... Read More

Convert Boolean to String in JavaScript

Shubham Vora
Updated on 10-Aug-2022 11:46:24

3K+ Views

In this tutorial, we will learn to convert the Boolean to string in JavaScript. The problem is straightforward: sometimes programmers need to use the boolean true and false values as a string. So, there is a requirement to convert the Boolean to string. Here, we have various methods to convert the Boolean to a string variable. Using the toString() Method Using + and $ (template literal) Operator Using the ternary Operator Using the toString() method The toString() method is the JavaScript string library method, which is useful for converting the variables to the string data type. We can ... Read More

Show Euro or Other HTML Entity in JavaScript Alert Windows

Shubham Vora
Updated on 10-Aug-2022 11:42:56

1K+ Views

This tutorial will teach us to show a euro or HTML entity in JavaScript alert Window. There are three pop-up windows in JavaScript. Alert box, Confirm box, and Prompt box. The alert box is useful to show some information to the user, such as a welcome message or user’s info. It contains the ok button, and when the user clicks on that, it closes. The confirm box is used to show the confirmation message. In many applications, you have seen that when you try to delete something, it shows the confirmation message. When you click on the ok, it returns ... Read More

Force Clients to Refresh JavaScript Files

Shubham Vora
Updated on 10-Aug-2022 11:36:46

12K+ Views

This tutorial teaches us to force clients to refresh JavaScript files. Now, the question is, why do we need to force clients to refresh the JavaScript files? Let’s understand it by example issue. Suppose we have deployed the application and lots of users are using our application. Now, to improve the performance and UI of the application, we will continuously work on our application and upgrade its version after every period. Obviously, after upgrading our application’s version, we will also push that into production. But sometimes, on the user's screen, client-side JavaScript or CSS is not upgraded, and it shows the ... Read More

Searching an Element in a Linked List Using C++

Prateek Jangid
Updated on 10-Aug-2022 10:09:30

6K+ Views

To search an element in a linked list, we must iterate through the complete list, compare each node with the desired data, and keep searching until a match is obtained. Because a Linked List does not provide random access, we must start the search from the first node. We are given a linked list of integers and an integer key. We need to find if this key exists in our linked list or not. We can do a simple linear search in the linked list and find the key. If present, we can return "Yes"; otherwise, "No" Let us look ... Read More

C++ Program to Represent the Fraction of Two Numbers in String Format

Prateek Jangid
Updated on 10-Aug-2022 10:04:34

1K+ Views

We are given two integer numerators and a denominator. We need to represent the fraction of these two integers in string format. If a certain decimal is repeating, we need a bracket to show its repeating sequence. Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Determine the integral quotient (absolute part before to the decimal point) before determining the fractional portion. Insert the remainder (numerator % denominator) in a map with the key being the remainder and the value being the index position at which this remainder occurs to see if ... Read More

Advertisements