Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: packages shared utils array ts migration #80

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const shuffleArray = array => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yauheni-deriv, Just a question, Why did you decide to switch from the arrow function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had error while trying to apply generic on arrow functions
https://www.typescriptlang.org/docs/handbook/2/functions.html

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn’t be any issues 🤔 Although it doesn’t matter and we can move forward 🙇🏻

export const shuffleArray = <T>(array: T[]): T[] => {
    for (let i = array.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [array[i], array[j]] = [array[j], array[i]];
    }

    return array;
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. will change it. I guess I just missed something while refactoring. it works fine

export function shuffleArray<T>(array: T[]): T[] {
if (Array.isArray(array)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be removed

for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
return array;
};
}