This tutorial will discuss how to write a Swift program to reverse a number. Reversing a number is a process in which the position of the digits of a number is interchanged to reverse their order. Below is a demonstration of the same − Suppose we enter the following input − Number = 098627 Following is the desired output − Reversed order = 726890 Algorithm Following is The algorithm to reverse the number − Step 1 − Start Step 2 − Create a variable named “number”. Now the value of the “number” variable is either user-defined or ... Read More
This tutorial will discuss how to write a Swift program to perform nCr(r-combination). nCr refers to r- combination. It is used to calculate the possible arrangements where the order of the selection does not matter. Or we can say that nCr is used to select r items from the set of n items where the order of the items does not consider. Formula Following is the formula of nCr nCr = (n!)/(r! * (n - r)!) Below is a demonstration of the same − Suppose we enter the following input. N = 5 R = 3 Following is the ... Read More
This tutorial will discuss how to write a Swift program to find the largest among three numbers. Given three numbers now we have to find the largest among the given three numbers. So we will compare all three numbers with each other to find the largest number. Below is a demonstration of the same − Suppose we enter the following input − 39, 87, 12 Following is the desired output − Largest number is 87 Finding largest number using max() function Swift provides an in-built method named as max() function. This function returns the maximum number ... Read More
This tutorial will discuss how to write a Swift program to find factorial of a number. A Factorial of a non-negative number is calculated by multiplying the number with every whole number till 1 for example, 6! = 6 x 5 x 4 x 3 x 2 x 1 = 720 which means the factorial of 6 is 720. The general form of factorial is − M! = m x (m - 1) x (m - 2) x (m - 3) …. X 1 Formula Following is the formula of factorial − M! = M * (M - 1)! ... Read More
The spread operator, which was first introduced in ES6, is used to unpack the elements of an iterable like an array. Cloning and merging the array is simple thanks to the spread operator. The spread operator could not be used with objects when it was first introduced in ES6. The spread operator was eventually extended to objects in ES2018. You'll learn how to use the JavaScript object spread (...) to clone an object or merge two objects into one in this article. In areas where 0+ arguments are expected, the spread operator allows an iterable to extend. This is most ... Read More
In JavaScript, a function is considered "curried" if it takes one or more arguments and returns a new function that expects the remaining arguments. Currying is a powerful technique that can be used to create new functions from existing ones, or to "uncurry" a function up to depth n. Why do we uncurry a function? There are several reasons why you might want to uncurry a function. For example, you may want to − Use a curried function in a context where a non-curried function is expected Convert a curried function to a non-curried form to make it easier ... Read More
In this article let us understand how to check whether a NaN is a NaN or not in JavaScript. Literal constant that is not quoted Not-a-Number is represented by NaN, a special value. NaN is commonly used to signal an error condition for a function that should return a valid number since it always compares unequally to any number, including NaN. Differentiating between different undefined values in JavaScript can be tricky. When working with NaN values in Boolean operations, there are a handful of difficulties to be careful of. The numeric type in JavaScript permits you to describe numbers of ... Read More
JavaScript's regular expression support is widely considered to be among the best in the world, but there's one area where it's lacking: there's no built-in way to clone a regular expression. This can be a problem when you need to create a new regular expression that is similar to an existing one but with a few small changes. The problem is that regular expressions are objects, and as such, they cannot be copied by simply assigning one to another. Consider the following code − var regex1 = /foo/; var regex2 = regex1; regex2 === regex1; // true In this ... Read More
In this tutorial, we will be discussing how to create a video slide animation effect using HTML, CSS, and JavaScript. This can be used to create a simple yet effective way to grab attention and engage viewers. Applying the Animation Effect To apply the animation effect, we will be using a keyframe rule. This will tell the browser to change the CSS properties of an element over a period of time. In our case, we want the video to slide across the screen, so we will be using the transform property. What is the Keyframe Rule? The keyframe rule is ... Read More
React and HTML have different ways of handling attributes. In React, some attributes are treated as JavaScript, while in HTML they are treated as strings. This can lead to confusion when working with React and HTML together. Why React Treats Some Attributes as JavaScript? React treats some attributes as JavaScript because they are used to modify the behavior of the component. For example, the "onClick" attribute is used to add an event listener to the element. In React, this attribute is treated as JavaScript, not as a string. How This Affects Working with React and HTML? This difference in handling ... Read More