Skip to content

Instantly share code, notes, and snippets.

@mrousavy
Last active January 28, 2022 22:59
Show Gist options
  • Save mrousavy/7d91630712d9a365c460f6ab7e60d191 to your computer and use it in GitHub Desktop.
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
/**
* 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