# Trending November 2023 # How Does Isnan() Function Works In Javascript? # Suggested December 2023 # Top 13 Popular

You are reading the article How Does Isnan() Function Works In Javascript? updated in November 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 How Does Isnan() Function Works In Javascript?

Introduction to isNaN() JavaScript

In this article, we will learn about isNaN() JavaScript. We will try to split the function isNaN() word by word and analyze the meaning of the function. is and NaN is both 2 separate words. NaN abbreviation is Not a Number. Now if we include any helping verb in front of any word, give a question right. Here also, isNaN means checks given value is a Number or Not. isNaN() checks whether the value passed to it is true or false.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

How does the isNaN() function work in JavaScript?

isNaN() function always checks whether the value is a Number or Not a Number.

isNaN() returns the Boolean value as output.

Returned Boolean values are true or false.

If the given value is a string, it returns true; if the given value is a number, it returns false.

isNaN(value);

value: Pass the required value to check whether it is a number or not.

Example: There is a situation if we want to add or subtract numbers. Let’s suppose the numbers we are getting are from 3rd party clients. Are we directly add or subtract those values? No, because We don’t know what those values are, whether numbers or strings. So, we first check whether it is a number or not by using the isNaN() function. If the number is in string form, we simply par the number. Later we will add or subtract.

Examples to Implement in isNaN() JavaScript

Below is the example of implementing in isNaN() JavaScript:

Example #1

Checking whether passing Strings are numbers or not

Code:

function checkStringsNumberOrNot() { var a=”Amardeep”; var b=”123″; var c=’25/12/2023′; var d=”123Param”; var e=”Hi989″; var f=”*&^%”; var g=123+”Hello”; } checkStringsNumberOrNot();

Output:

Explanation of the above code: Amardeep is not a number, so the function returns true. 123 is a number, so the function returns false. 25/12/2023 is not a number but a date, so the function returns true. 123Param is not a number, so the function returns true. Hi989 is not a number, so the function returns true. 8&^% is not a number, so the function returns true. 123Hello is not a number, so the function returns true. (123+” String”=String so becomes 123Hello).

Example #2

Checking whether passing integers are numbers or not

Code:

function checkIntegersNumberOrNot() { var a=”989″; var b=23; var c=-25; var d=-5.21; var e=’+28.67F’; var f=”87.23L”; var g=’0′; } checkIntegersNumberOrNot();

Explanation of the above code: 989 is a number, so the function returns false. 23 is a number, so the function returns false. -25 is a number, so the function returns false. -5.21 is a number, so the function returns false. +28.67F is not a number, so the function returns true. 23L is not a number, so the function returns true. 0 is a number, so the function returns

Note: Whereas in Java, suffixes F and L indicate float and long numbers, respectively, JavaScript doesn’t.

Example #3

Checking whether passing predefined JavaScript values are numbers or not

Code:

function checkPredefinedValuesNumberOrNot() { var a=”true”; var b=”false”; var c=”undefined”; var d=”null”; var e=0/0; var f=NaN; var g=”NaN”; } checkPredefinedValuesNumberOrNot();

Output:

Explanation of the above code: true is not a number, so the function returns true. false is not a number, so the function returns true. Undefined is not a number, so the function returns true. null is not a number, so the function returns true. NaN(0/0) is not a number, so the function returns true. NaN without quotes is not a number, so the function returns true. NaN with quotes is not a number, so the function returns true.

Example #4

Its checks passed value is NaN, and its type is number. It is an updated version of the isNaN() direct-using function. It also returns true or false based on the value provided to it.

Code:

function checkValuesNumberOrNot() { var a=10; var b=”false”; var c=0/0; var d=-21.7; var e=Number.NaN } checkValuesNumberOrNot();

Output:

Explanation of the above code: 10 is a number, so the function returns false. false is a number, so the function returns false. NaN (0/0) is not a number, so the function returns true. -21.7 is a number, so the function returns false. NaN (Number.NaN) is not a number, so the function returns true.

Note:

Number.isNaN() returns the false and true output as false only because it considers false as 0 and true as 1 here.

Function isNaN continuously checks whether the value inside the function is a number or not, whether in single quotes, double quotes, or no quotes.

Conclusion

isNaN() function is used to figure out whether a given value is a number or not. If the given value is a number, then return false otherwise, return true.

Recommended Articles

This is a guide to isNaN() JavaScript. Here we discuss an introduction, how isNaN() JavaScript works, and examples to implement. You can also go through our other related articles to learn more –

You're reading How Does Isnan() Function Works In Javascript?

## Learn How Does The Numpy.clip() Function Works?

Introduction to Numpy.clip() in Python

Web development, programming languages, Software testing & others

In simpler terms for an interval specified (for instance : [0, 1]) the values that are greater than 1 shall deem to become one and the ones smaller than zero shall deem to become zero. In comparison to using the function min() and max() and checking their comparatives by maximum(), the clip() serves a much quicker and more comprehensive solution when compared to running the while loop.

Syntax and Parameters for Numpy clip()

Following syntax is used structurally to construct code in python language:

numpy.clip (arr, a _min, a_max , out = None)

Following are the parameters that are used in the syntax for numpy.clip() function in Python:

Parameters Description

array ( here arr) (alternatively, can be specified within the code itself)

(Scalar value, keyword: “arraylike” or keyword: “None”) If NONE is specified then the lowest element of the array would be considered to be the smallest element in the array entered. It has to be noted that the parameter NONE should not be specified for both a_min and a_max.  If either one of the parameters is kept as ARRAYLIKE it results in 3 different arrays being broadcast.

(Scalar value, keyword: “arraylike” or keyword: “None”) The highest value to be put for the array limit is the upper extent with which the array elements have been checked if they are larger than the lower limit.

Return Value when running through Numpy.clip()

This Numpy.clip() function returns a two-dimensional array that has been specialized from the string of elements that have been presented in the array.

numpy.clip ( arr,a_ min, a _ max, out  = None )

Returns: Here the lower values are replaced by a_min values and higher limits are replaced by a_max

Example of Numpy.clip()

Code:

# To demonstrate the usage of the Numpy clip () function in python language # calling the Numpy by importing it to perform the clip function import numpy as N1 Ar_array = [10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ] print ("Please enter the elements for the array :- ", Ar_array ) Output_array = N1.clip(Ar_array, a_min = 20 , a_max = 60 ) print ("The new clipped array will be : " ) print Output_array

The output of the above-given code is as follows:

How does the Numpy.clip() function work?

It is found in a lot of data concerning issues and algorithmic functionalities (for instance the Proximal Policy Optimization or PPO used in algorithms of reinforcement learning) where there is a need to limit the elements under an upper or lower value or both.

The numpy clip serves the purpose of delivering a pre-built functionality of limiting the values.

The following diagram pictographically displays how the clip function actually works and gives an insight into its mechanism of limiting

Fig: The image here displays how the default values using index numbers are identified and put under the clipped limit values

The system first analyses the values present in the array entered by the user

It then checks the limits for both the upper value and lower value

It then compares with each element if it does not confer to the limits and checks for their index with respect to the initial array entered

It changes the defaulting dex number to the upper limits and lowers limits specified.

Finally, it changes the values with the replaced limited values and makes a new array that suffices the need specified for the function to be performed by the user

Conclusion

The numpy clip function serves as one argument/liner solution to give clipped arguments for arrays which are frequently required by various algorithms which in a wat reduce the computational time needed to run code. It also decreases the verbosity of the code making it better for large data analysis.

Recommended Articles

This is a guide to Numpy.clip(). Here we discuss introduction, syntax, parameters and working of Numpy.clip() function along with the examples. You may also have a look at the following articles to learn more –

## How Find_In_Set() Function Works In Mysql?

Introduction to MySQL FIND_IN_SET()

MySQL FIND_IN_SET() function is a built-in MySQL string function responsible for discovering the position of a given specific string provided in a list of strings separated by a comma. The FIND_IN_SET() function accepts two arguments that allow matching the first value with the second one containing a list of values as substrings separated by a comma character.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Generally, the FIND_IN_SET() function applies to any field in the database table with a sequence of values differentiated by a comma. The user wants to compare those values with a specific single value. It thus returns the index of the matched string within the list.

Syntax

Following is the syntax structure that illustrates the use of the FIND_IN_SET() function in the MySQL server:

FIND_IN_SET(string1, stringlist);

The initial parameter named string1 defines the string which you need to find.

The next parameter, “stringlist,” represents the list of strings that must be examined, and commas separate these strings.

According to the value of the function arguments, the MySQL FIND_IN_SET() will return the value as an integer or a NULL:

If either function’s parameters, i.e., string1 or stringlist, have a NULL value, the function results in a NULL value.

The function will return zero if the stringlist is empty or if the string1 parameter is not found in the stringlist.

The function returns a positive integer value if the string1 parameter is available in the stringlist.

But note that if the string1 consists of a comma(,), the FIND_IN_SET() function performs poorly on execution. If the string1 parameter is a constant string and the stringlist parameter represents a SET column type, the MySQL server will optimize using bit arithmetic.

How does the FIND_IN_SET() function works in MySQL?

MySQL consists of many databases, and each database comprises different tables. Tables in MySQL store data in various data types supported by MySQL, and the most commonly used types are integers and strings.

When a MySQL user wants to find out if a specific string exits in any of certain sequences of strings divided by a comma(,) symbol aimed for any query execution, then the built-in MySQL string function FIND_IN_SET() can be applied.

This function provides the required value depending on the search results. For example, suppose we are illustrating the following query to show how the function works in MySQL:

We will search a substring h within a list of strings using the statement below,

SELECT FIND_IN_SET("h", "g,h,k,l");

We use the SELECT statement with the FIND_IN_SET() function to evaluate and display the return value. The result from the above query is true as the first parameter, ‘h’ is present in the list as the second parameter. So, Upon execution, the function will produce a positive integer, specifically 2. This is because the first value of the FIND_IN_SET() function is found in the second index of the list of values provided in the function’s second parameter, which is ‘g,h,k,l’.

Similarly, if we take the below query, then the function returns 0 as the output value as the value is not in the list:

SELECT FIND_IN_SET("b", "g,h,k,l");

Also, when we define the query as follows then, the output is NULL as the second parameter is NULL:

SELECT FIND_IN_SET("h", NULL);

Thus, we can define the position of a string within a particular list of substrings provided by the database tables.

Conversely, the MySQL IN operator takes any number of arguments to show if a value matches any value in a set.

Examples of MySQL FIND_IN_SET()

Let us demonstrate some examples using the MySQL FIND_IN_SET() as follows:

Example #1

Example to fetch data from a table by MySQL FIND_IN_SET() function:

Suppose we have a table named collection created in our database using the query below:

CREATE TABLE IF NOT EXISTS Collection (ColID INT AUTO_INCREMENT PRIMARY KEY, ColName VARCHAR(255) NOT NULL, Subjects VARCHAR(255) NOT NULL);

Also, let us enter a few record rows into the Collection table created:

INSERT INTO Collection (ColName, Subjects) VALUES('o-1','Computers, Maths, Science'),('o-2','Networks, Maths, MySQL'),('o-3',' Computers, English, Data Science'),('o-4','Electric, Maths, Science'),('o-5','Computers, MySQL, English'),('o-6','Science, Web Design'),('o-7','Maths, Science'),('o-8','MySQL, Web Design'),('o-9','Computers');

Displaying the contents of the table as follows:

SELECT * FROM Collection;

Now, we will find the collection that will accept the Maths subject using the MySQL function FIND_IN_SET() shown below:

SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET('Computers', Subjects);

Output:

Looking for a simple example and its output as follows:

SELECT FIND_IN_SET('h', 'g,h,k,l');

Output:

The FIND_IN_SET() function provides the position of the first argument ‘h’ as found in the sequence of values as the second argument of the function.

Example #2

Example showing Negativity of MySQL FIND_IN_SET() function:

Considering the previous table, the result value of the function will be empty when MySQL returns false. This occurs when the substring specified in the first argument is not found in the list of values provided as the second argument. Thus, we will apply the MySQL NOT operator to negate the MySQL function FIND_IN_SET(). Finally, we will illustrate the query example with FIND_IN_SET() function using the NOT operator also to search the collection that does not match the PHP subject in the table values:

SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET('PHP', Subjects);

As you can see, no output is produced as a collection because, in the list of values from column Subjects, the FIND_IN_SET() function has not found any matched substring as given in the first argument.

Example #3

Difference between IN operator and FIND_IN_SET():

The IN operator defines whether a substring matches any substring set or list and can accept any number of arguments parted by a comma as follows:

SELECT ColName, Subjects FROM Collection WHERE ColName IN ('o-1', 'o-2', 'o-5', 'o-6');

Output:

Similarly, using the FIND_IN_SET() will result in the identical output as IN query but takes only two parameters to show a match of value with a list of values divided by a comma:

SELECT ColName, Subjects FROM Collection WHERE FIND_IN_SET(ColName, 'o-1,o-2,o-5,o-6');

Output:

Conclusion

MySQL FIND_IN_SET() function allows a server to check if a substring as the first argument is present in the list of values composed of substrings in the second argument parted by a comma.

This function, when the value is searched, returns the results based on those values as a positive integer as position(if the value exists in the list), zero(if value not found) or NULL(if any argument is NULL), which can be helpful for MySQL operations at the admin level.

Recommended Articles

We hope that this EDUCBA information on “MySQL FIND_IN_SET()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

## How Nullif Function Works In Postgresql?

Definition of PostgreSQL NULLIF

PostgreSQL nullif is a common conditional expression used to handle null values or expressions in PostgreSQL. nullif is also used with the coalesce function to handle the null values. PostgreSQL nullif function returns a null value if provided expressions are equal. If two expressions provided are equal, then it provides a null value; as a result, otherwise, it will return the first expression as a result.

Start Your Free Data Science Course

Syntax:

Below is the syntax of the nullif function as follows.

Select (Argument1 (First value which is used to handle null values), Argument2 (Second value which is used to handle null values)) SELECT Column1, …, ColumnN COALESCE ( NULLIF (Column_name, ''),   ) FROM table_name;

Parameter:

Select: In PostgreSQL, you can use the NULLIF function with the SELECT statement to fetch data from a table while handling null values or expressions. We can use multiple columns or a single column at one time to fetch data from the table.

Coalesce: Coalesce states that function name in PostgreSQL, which returns as a first non-null value. Coalesce function is essential and useful in PostgreSQL.

We have used coalesce function with nullif function in PostgreSQL.

Argument 1 to Argument 2: Argument is nothing but an integer or character value that we have passing with nullif function. If we have passing two-argument and both contain a different value, then the nullif function will return the first value in a result. If we have to pass both the same values, then it will return a null value as a result.

Column 1 to Column N: This is the table’s column name. If we want to fetch data from a table using nullif function in PostgreSQL, we pass multiple columns simultaneously. Also, we have given the column name with the nullif function in PostgreSQL.

From:  In PostgreSQL, you can retrieve data from the keyword FROM with the table name in a SELECT query.

Table name: Table name used with nullif function to fetch data from a table.

Nullif: It is used to handle null values in PostgreSQL; nullif is also used with the coalesce function to handle the null values. nullif function returns a null value if provided expressions are equal; if provided two expressions are equal, then it provides a null value; otherwise, it will return the first expression as a result.

How does NULLIF Function work in PostgreSQL?

Below is the working of nullif function in PostgreSQL.

We can use the coalesce function with nullif function in PostgreSQL. Coalesce states that the function name in PostgreSQL which returns as first non-null value as a result. Coalesce function is essential and useful in PostgreSQL.

In PostgreSQL, you can use the common conditional expression NULLIF to handle null values or expressions.

If we have passing two nullif function arguments and the first contains a null value, then the nullif function will return the first value in a result. If we pass both the same value, it will return a null value in a result.

We have used the nullif function in PostgreSQL to prevent the division error by zero.

In PostgreSQL, you can use the nullif function to prevent errors that may occur when comparing two values.

Examples

Below is an example of nullif function.

We have using a discount table to describe an example of the nullif function as follows.

Below is the data description of the discount table, which we have used to describe an example of nullif function.

Example #1 testing=# select * from discount;

Output:

Example #2

In the below example, we have passing values like 50 and 50. The nullif function will return null values because both the arguments which we have passing are the same.

testing=# select nullif (50, 50);

In the above example, we pass the same argument with the nullif function so that it will return the null value as a result.

Example #3

In the below example, we have passing values as 50 and 100. Nullif function will return the first value, i.e., 50 because both the arguments which we have passing are different.

testing=# select nullif (50, 100);

Output:

In the above example, we have a different passing argument with the nullif function so that it will return the first value as a result.

Example #4 testing=# select nullif ('A',  'P');

Output:

In the above example, we have a passing different argument with the nullif function so that it will return the first value as a result.

Example #5

In the below example, we have to retrieve data from a discount table using the nullif function.

testing=# SELECT cust_id, product_name, COALESCE ( NULLIF (Product_price, '')) AS Product_price FROM discount;

Output:

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL NULLIF” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

## How Addslashes() Function Works In Php?

addslashes() function is an inbuild and pre-defined function in PHP which is used for returning a string containing backlashes and is prefixed before all predefined characters present within the string. PHP addslashes() function has a special characteristic that it does not consider any parameters or arguments to be passed from the function. The predefined characters behave differently in this function. addslashes function somewhat differently in comparison to the addcslashes() function because this function accepts specified characters that need to be added before the slashes but is not important for addslashes() function as it doesn’t allow any parameter to pass and appends the slash before the specified character.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

addslashes(): The addslashes() function allows only one parameter or argument to be passed from within the function followed by the \$ symbol of string.

\$string : This is the argument that will be passed to the addslashes function as an input to the function. it specifies a special structure of the attribute designating the string.

How addslashes() function works in PHP?

addslashes is a special inbuild function in the PHP defined string references and string packages which generates a quote for the quote string with slashes. It has a return type which returns the string with a special format in a way that the characters within the string will be prefixed following a string of characters:

Single quote: It is represented by a symbol (‘)

Double quote: It is represented by a symbol (” “)

Backslash: It is represented by a symbol ( )

Null: It is represented by the (NUL byte)

Use cases will vary with the string of characters in a way that the characters that will be prefixed before the string with these characters will be escaped set of characters.

This function has been added and came into its usage after PHP version 5.4.0 and above, otherwise, the default value was being considered as magic_quotes_gpc on all types of GET, POST, and cookies being used on the string as mentioned for addslashes() function.

Sometimes this function behaves abnormally once incorporated with the database queries. Therefore, it depends on the type of requirement and versions to check and cope up with the addslashes function once it is in use with PHP. Since this makes it ambiguous to make it work with databases there are times or scenario that may arise for making it sync with Database injection and its related queries at that time it is very much needed to make database-specific escaped functions or prepared statements for its use.

Moreover, many substrings which act or are a part of the addslashes function which includes following function as its companion:

stripcslashes(): It is a function as part of addslashes which is used to generate some un-quoted string but are quoted with some addcslashes.

stripslashes(): It is also a companion of addslashes function which unquote any of the generated quoted string.

addcslashes(): It is another part of addslashes function which works totally complimentary with the addslashes function in a way that it quotes string with inbuild function including a C style pattern for it.

htmlspecialchars(): This function works in a way that a special character gets converted into HTML entities.

Quotemeta(): This function works for characters within characters which are called meta characters type.

get_magic_quotes_gpc(): This function also behaves in a similar fashion with a very less difference of present settings in configuration for setting of magic_quotes_gpc.

Below are the different examples :

Example #1

This program represents the addslashes function for the representation of the string with an output of the generated string with escaped sequences of characters.

Code:

<?php \$str = addslashes(‘hope you are doing good with educba!’); echo(\$str);

Output:

Example #2

This program represents the addslashes function for the representation of the string with an output of the generated string with escaped sequences of characters but supporting the ambiguous behavior of the database injection.

Code:

<?php \$str = “Which car is Volkswaon?”; echo addslashes(\$str) . “  Safe for database injection.”;

Example #3

This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter W which behaves completely opposite of addslashes() function.

Code:

<?php \$str = addcslashes(“Welcome Educba!”,”W”); echo(\$str);

Output:

Example #4

This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter educba for adding backslashes which behave completely opposite of addslashes() function.

Code:

<?php \$str = “Thanks for revisiting the educba portal!”;

Output:

Example #5

Code:

<?php \$str = “Thanks for revisiting to our portal of educba!”; echo addcslashes(\$str,’a..g’);

Output:

Example #6

This program represents the HTML special characters with the elements to translate the element’s value into one value using string.

Code:

<?php \$str = “There are some good person.”; echo htmlspecialchars(\$str);

Output:

Conclusion

The addslashes function is used to represent and traverse the string by prefixing the backslash string in front of the entire special character string and is used to quote the necessary and important string to be used simultaneously.

Recommended Articles

This is a guide to PHP addslashes(). Here we discuss how addslashes() function works in PHP along with multiple examples and its code implementation. You may also have a look at the following articles to learn more –

## How Reduce Function Works In Kotlin

Introduction to Kotlin reduce

Web development, programming languages, Software testing & others

Syntax

The kotlin language has many default methods. Keywords and operators create the application deployment, and it’s faster compared to java type of applications. It’s a lightweight component that prevents the applications from increasing memory sizes.

fun main() { val vars -----some codes which depends on the requirement---- }

The above codes are the basic syntax for the kotlin reduce() function used on the main method. We can import the packages based on the classes and methods which will use in the code. The reduce() function reduces the sizes and prints the values on the output console.

How does reduce Function Work in Kotlin?

The kotlin language is cross-platform and a Java standard library, but the type is inference. The reduce() is one of the built-in functions that accumulates the values. It may be of any type, like an integer or number, strings starting with the index element, and it applies the code operation from left to the right set of values will be assigned for each set of elements. The values declared by the specific variable types will be array types; the value starts from the index 0.

Using the reduceIndexed() function also returns the array index; if the array is empty, it throws the exception and returns the null value if the array value is empty. The function parameter is a must for the function invoked and each subsequent data element on the group. The data is to be key-value pair formats like a map it associates with the key of each type of group with the formatted results of accumulating the group elements on the stack memory because the method performs the operation that is related to the memory areas for storing the complex values into the single set format values.

Examples of Kotlin reduce

Given below are the examples:

Example #1

Code:

import kotlin.collections.* fun main() { val x = listOf(12,34,56,78,90,627, 54,56,65324,65,62145) println("Have a Nice Day users its the first example regarding the reduce() "+y) println("Thank you users for spenting the time please try again "+z) val ab = listOf("First", "Welcome", "To", "My","Domain") val ef = listOf("second", "Please", "Try", "Again","Have", "A", "Nice", "Day", "Users","123","456","789") }

Output:

In the above example, we used some collection with the reduce() method to reduce the lines from left to right. Currently, the reduce() method converts the values like integer numbers into the single set of values stored on the variable.

Example #2

Code:

import kotlin.collections.* try { val p = intArrayOf(11, 22, 33, 44, 55, 66, 77, 88, 99) println(p.sum()) var x = 0 p.forEach { x += it } println(x) val vars = 11/ 0 println(vars) } catch (ex: ArithmeticException) { println(ex) } finally { println("If above two blocks are not executing means the finally block will execute") } println("This is a Second Example") var w: String = "Welcome To My Domain its a Second Example for to use the reduce() method in Kotlin java library" println("Have a Nice Day users : \$w") var u: String? = "Thank you for choosing our application Please try again" println("Its a Second variable \$u") u = null println("If the variable is going to be null : \$u") }

Output:

Example #3

Code:

package one val example1: Int = 33 val example2: Int = 53 val sum = example1 + example2 println("The sum is: \$sum") val example3 = listOf("first", "second", "third", "four", "five", "six", "seven", "eight", "nine", "ten") val example4 = example3.groupingBy { it.first() } }) val example5 = example4.values.sortedBy { it.first } println(example5) val example6 = listOf("first", "second", "third", "four", "five", "six", "seven", "eight", "nine", "ten") val example7 = example3.groupingBy { it.first() } println(example7) val nums = listOf(44, 45, 43, 22, 11, 72, 61, 83, 94) mp.put(1, "siva") mp.put(2, "raman") mp.put(3, "welcome") mp.put(4, "users") mp.put(5, "have") mp.put(6, "a") mp.put(7, "nice") mp.put(8, "day") val akeys = ArrayList(mp.keys) val avalues = ArrayList(mp.values) println("Your input keys are : \$akeys") println("Your input values are: \$avalues") val y = listOf("four", "five", "six", "second", "first", "seven", "eight", "nine", "ten") println(res) }

Output:

In the final example, we used the collection concepts like list and map and converted the map values to the list collection. Here we used to reduce() and reduceRight() methods for reducing the code lines from left to right and right to left.

Conclusion

In the kotlin language, we used some default methods, keywords, and variables, which regarding the separate packages, include classes and methods. For that, the reduce() and other similar methods are the default methods for reducing the datas into a single set in the collections, util, and other default packages, which depend on the user requirement.

Recommended Articles

We hope that this EDUCBA information on “Kotlin reduce” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about How Does Isnan() Function Works In Javascript? on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!