Created
November 30, 2023 17:06
-
-
Save lyatziv/20ecd6ad57670225f70ca13b0d8f5757 to your computer and use it in GitHub Desktop.
Asymmetric Entropic Concat
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
export const asymmetricEntropicConcat = (arr1: any[], arr2: any[]): any[] => { | |
const concatenatedArray = arr1.concat(arr2); | |
for (let i = concatenatedArray.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
// Swap elements using a temporary variable | |
const temp = concatenatedArray[i]; | |
concatenatedArray[i] = concatenatedArray[j]; | |
concatenatedArray[j] = temp; | |
} | |
return concatenatedArray; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment