11/19/2023 0 Comments Slice array javascript![]() It starts with 0 index that is first element and retrieves all elements until 2 means index = 1 that’s why we got 0th element and 1st element here. It’s length = 5 Let us play with slice function now. Int of Array with 5 values are created so it’s index start value is 0 and index end value is 4. Array slice Function Examples: scala> val marksArray = Array(56,79,60,99,71) Here ‘from’ is the starting index (Inclusive) of the Array and ‘until’ is the ending index (Exclusive) of the Array. In Scala API, Array class defines slice function as follows: def slice(from: Int, until: Int): Array Here elements numbers for an Array of Numbers, Characters for a String, an object for a Collection. ![]() Slice function extract elements starting from ‘first-index’ (Inclusive) to ‘until-index’ (exclusive). It should be zero or any any positive integer less than the length of the Collection or String or Array. Slice function Parameters: The “slice” function parameter’s usage are described in the following table: def slice(from-index: Int, until-index: Int): Seq Example:- The following function is defined in Scala API’s Seq class. Here “ScalaAPIClass” means any Scala Collection class (which supports index based access like Seq, List etc), String, Array classes. Here Bread.slice(0,10) means take bread slices from 0 to 9 so total 10 Bread slices.(Just to resemble Scala’s slice function here I’m using zero, but assume this as one.) slice function syntax: In Scala Standard Library (API), this slice function is defined as follows: def slice(from-index: Int, until-index: Int): ScalaAPIClass Real-world slice scenario:- We can use this slice function in our regular real-world life too as shown below. It takes two parameters of “Int” type and returns subset or whole or none element(s) of original Collection (or String or Array). In Scala API, ‘slice’ function is used to select an interval of elements. We will pick-up each API and discuss them in-depth with suitable examples in next section. Scala slice function is available in the following API classes: ![]() ![]() Today we will look into Scala slice function. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |