Extra: if you dont have to increase the divisor up to the number. You can stop much earlier. Step-1: Any number will not be divisible by a number bigger than half of it. For example, 13 will never be divisible by 7, 8, 9. It could be as big as half of it for even number. For example, 16 will be divisible by 8 but will never be by 9, 10, 11, 12. Since JavaScript is a functional language, functions are objects too. As a result, Functions can also be used as either Key and/or Value on your dictionary. For the Dictionary Key, this really does make sense since the Dictionary is really just an Object which can have functions/methods on it.
-->Definition
Reverses the order of the elements in a one-dimensional Array or in a portion of the Array.
Overloads
Reverse(Array, Int32, Int32)Reverse(Array, Int32, Int32)Reverse(Array, Int32, Int32) | Reverses the sequence of the elements in a range of elements in the one-dimensional Array. |
Reverse(Array)Reverse(Array)Reverse(Array) | Reverses the sequence of the elements in the entire one-dimensional Array. |
Reverse<T>(T[])Reverse<T>(T[])Reverse<T>(T[])Reverse<T>(T[]) | |
Reverse<T>(T[], Int32, Int32)Reverse<T>(T[], Int32, Int32)Reverse<T>(T[], Int32, Int32)Reverse<T>(T[], Int32, Int32) |
Reverse(Array, Int32, Int32)Reverse(Array, Int32, Int32)Reverse(Array, Int32, Int32)
Reverses the sequence of the elements in a range of elements in the one-dimensional Array.
Parameters
- array
- ArrayArrayArrayArray
The one-dimensional Array to reverse.
![Search Search](/uploads/1/2/4/8/124881807/517229595.jpg)
- index
- Int32Int32Int32Int32
The starting index of the section to reverse.
- length
- Int32Int32Int32Int32
The number of elements in the section to reverse.
Exceptions
ArgumentNullExceptionArgumentNullExceptionArgumentNullExceptionArgumentNullException
array
is null
.RankExceptionRankExceptionRankExceptionRankException
array
is multidimensional.ArgumentOutOfRangeExceptionArgumentOutOfRangeExceptionArgumentOutOfRangeExceptionArgumentOutOfRangeException
index
is less than the lower bound of array
. -or-
length
is less than zero.ArgumentExceptionArgumentExceptionArgumentExceptionArgumentException
index
and length
do not specify a valid range in array
.Examples
The following code example shows how to reverse the sort of the values in a range of elements in an Array.
![Js reverse search Js reverse search](/uploads/1/2/4/8/124881807/356136422.jpg)
Remarks
After a call to this method, the element at
myArray[i]
, where i
is any index in the array, moves to myArray[j]
, where j
equals (myArray.Length + myArray.GetLowerBound(0)) - (i - myArray.GetLowerBound(0)) - 1
. The Reverse method can be used to reverse a jagged array.
This method is an O(
n
) operation, where n
is length
.Reverses the sequence of the elements in the entire one-dimensional Array.
Parameters
- array
- ArrayArrayArrayArray
The one-dimensional Array to reverse.
Exceptions
ArgumentNullExceptionArgumentNullExceptionArgumentNullExceptionArgumentNullException
array
is null
.RankExceptionRankExceptionRankExceptionRankException
array
is multidimensional.Examples
The following code example shows how to reverse the sort of the values in an Array.
Remarks
After a call to this method, the element at
myArray[i]
, where i
is any index in the array, moves to myArray[j]
, where j
equals (myArray.Length + myArray.GetLowerBound(0)) - (i - myArray.GetLowerBound(0)) - 1
. This method is an O(
n
) operation, where n
is the Length of array
. As the following example shows, the Reverse method can be used to reverse a jagged array. It initializes a jagged array with one element for each month of the current year in the current culture's calendar. Each element contains an array with as many elements as that month has days. The example displays the contents of the array, calls the Reverse method, and then displays the contents of the reversed array.
Reverse<T>(T[])Reverse<T>(T[])Reverse<T>(T[])Reverse<T>(T[])
Type Parameters
Parameters
- array
- T[]
Reverse<T>(T[], Int32, Int32)Reverse<T>(T[], Int32, Int32)Reverse<T>(T[], Int32, Int32)Reverse<T>(T[], Int32, Int32)
Type Parameters
Parameters
- array
- T[]
- length
- Int32Int32Int32Int32