Preserve Leading 0 with JavaScript Numbers

Shubham Vora
Updated on 20-Oct-2022 08:23:14

4K+ Views

In this tutorial, we will learn how to preserve leading 0 with JavaScript numbers. Sometimes we need to sort strings that are similar to numbers. For example, 10 comes before 2, but after 02 in the alphabet. Leading zeros are used to align numbers in ascending order with alphabetical order. Following are the methods used to preserve leading zero with JavaScript numbers. Using the Number as a String The number is converted into a string using string manipulation, and the leading zero is preserved. Syntax myFunc2('Neel', 27, '0165') The function myFunc2() is called, and the values are passed ... Read More

Check if a Dictionary is Empty in Swift

Ankita Saini
Updated on 20-Oct-2022 08:22:29

2K+ Views

This tutorial will discuss how to write swift program to check the dictionary is empty. A dictionary is used to store data in the form of key-value pair in the collation without any defined-order. Here the type of the keys are same as well as the type of the values are also same. Each key is behave like an identifier for the associate value inside the dictionary and each value has a unique key. Swift dictionary is just like the real dictionary. It loop up values according to their identifier. Syntax Following is the syntax for creating dictionary − var ... Read More

Find the Size of a Dictionary in Swift

Ankita Saini
Updated on 20-Oct-2022 08:21:01

1K+ Views

This tutorial will discuss how to write swift program to find the size of dictionary. A dictionary is used to store data in the form of key-value pair in the collation without any defined-order. Here the type of the keys are same as well as the type of the values are also same. Each key is behave like an identifier for the associate value inside the dictionary and each value has a unique key. Swift dictionary is just like the real dictionary. It loop up values according to their identifier. Syntax Following is the syntax for creating dictionary − var ... Read More

Display Armstrong Numbers Between Intervals Using Function in Swift

Ankita Saini
Updated on 20-Oct-2022 08:19:43

366 Views

This tutorial will discuss how to write Swift program to display Armstrong numbers between intervals using function The sum of nth power of individual digit of a number is equal to the number itself, then such type of number is known as Armstrong number. Suppose we have a number 407 so here n = 3 407 = 43 + 03 + 73 407 = 64 + 0 +343 407 = 407 Hence 407 is Armstrong number Suppose we have another number 2346, so here n = 4 2346 = 24 + 34 + 44 + 64 2346 = 16 + ... Read More

Pass Undefined Value to Function with Multiple Parameters in JavaScript

Shubham Vora
Updated on 20-Oct-2022 08:18:41

4K+ Views

In this tutorial, we will learn how to pass the value 'undefined' to a function with multiple parameters in JavaScript. In JavaScript, the data type of 'undefined' is primitive. When a variable is declared, JavaScript automatically assigns the value 'undefined' to it. If a function has multiple parameters and one of the parameters' values is not available at the moment, then we need to omit that parameter's value from the function call. But if we omit the parameter's value with a blank space, the JavaScript will show an error. Syntax function abc(param1, param2, param3) { console.log(param1, ... Read More

Check Armstrong Number in Swift

Ankita Saini
Updated on 20-Oct-2022 08:18:16

1K+ Views

This tutorial will discuss how to write swift program to check Armstrong number. The sum of nth power of individual digit of a number is equal to the number itself, then such type of number is known as Armstrong number. Suppose we have a number 407 so here n = 3 153 = 13 + 53 + 33 153 = 1 + 125 + 27 153 = 153 Hence 153 is Armstrong number Suppose we have another number 8973, so here n = 4 8973 = 84 + 94 + 74 + 34 8973 = 4096 + 6561 + 2401 ... Read More

Display Armstrong Number Between Two Intervals in Swift

Ankita Saini
Updated on 20-Oct-2022 08:16:41

451 Views

This tutorial will discuss how to write swift program to display Armstrong number between two intervals. The sum of nth power of individual digit of a number is equal to the number itself, then such type of number is known as Armstrong number. Suppose we have a number 407 so here n = 3 407 = 43 + 03 + 73 407 = 64 + 0 +343 407 =407 Hence 407 is Armstrong number Suppose we have another number 2346, so here n = 4 2346 = 24 + 34 + 44 + 64 2346 = 16 + 81 + ... Read More

Manipulate JavaScript's Date Object

Shubham Vora
Updated on 20-Oct-2022 08:14:50

3K+ Views

To manipulate JavaScript’s Date object, you can either use get or set method and properties. For example, to set hours or to get minutes in JavaScript. Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time. Here is a list of the methods used to Date and their description. Sr.No Methods & Description 1 date() Returns today's date ... Read More

Find Geometric Mean of Numbers in Swift

Ankita Saini
Updated on 20-Oct-2022 08:14:29

357 Views

This tutorial will discuss how to write swift program to find the geometric mean of the numbers. Geometric mean also known as GM. Geometric mean is defined as the xth root of the product of x numbers. Suppose we have x elements(that are, a1, a2, a3, ....ax) in the given array, then the geometric mean is − GM = (a1 * a2 * a3 * a4 * ....*ax)1/x Below is a demonstration of the same − Input Suppose our given input is − MyVal = [34, 67, 2, 45, 8, 12] Output The desired output would be − Geometric ... Read More

Find Harmonic Mean of Numbers in Swift

Ankita Saini
Updated on 20-Oct-2022 08:13:24

312 Views

This tutorial will discuss how to write swift program to find the harmonic mean of the numbers. Harmonic mean also known as HM is defined as the reciprocal of the average of reciprocal. Or we can say that harmonic mean is the reciprocal of the arithmetic mean by their reciprocal. Suppose a1, a2, a3, a4, .....an are the n-elements of a collection then the harmonic means is − HM = n/[(1/a1) + 1/(a2) + 1/(a3) + 1/(a4)+...+ 1/(an)] Below is a demonstration of the same − Input Suppose our given input is − MyVal = [3.4, 1.2, 7.8, 4.5, 2.4] ... Read More

Advertisements