Skip to content

Instantly share code, notes, and snippets.

@lyatziv
Created November 30, 2023 17:06
Show Gist options
  • Save lyatziv/20ecd6ad57670225f70ca13b0d8f5757 to your computer and use it in GitHub Desktop.
Save lyatziv/20ecd6ad57670225f70ca13b0d8f5757 to your computer and use it in GitHub Desktop.
Asymmetric Entropic Concat
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