Last active
January 28, 2022 22:59
-
-
Save mrousavy/7d91630712d9a365c460f6ab7e60d191 to your computer and use it in GitHub Desktop.
A JS function that returns a copy of the input Array in reversed order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a reversed copy of the given Array | |
*/ | |
export function fastReverse<T>(arr: T[]): T[] { | |
const result = new Array<T>(arr.length); | |
for (let i = 0; i < arr.length; i++) { | |
result[i] = arr[arr.length - 1 - i]; | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment