Skip to content

Instantly share code, notes, and snippets.

@sungchuni
Created November 11, 2020 14:55
Show Gist options
  • Save sungchuni/baeb994f146c89bbf8cdafc12f64fec8 to your computer and use it in GitHub Desktop.
Save sungchuni/baeb994f146c89bbf8cdafc12f64fec8 to your computer and use it in GitHub Desktop.
무작위 정렬을 수행할 것이라 예상하는 방식이 얼만큼 무효한지를 검증하기 위한 함수
function computeAverageRandomSort(length = 16, iteration = 1024) {
function generateRandomArray() {
return Array.from({length})
.map((_, i) => i)
.sort(() => Math.random() - .5);
}
const arrays = Array.from({length: iteration}).map(generateRandomArray);
return Array.from({length}).map(
(_, i) =>
arrays.map(array => array[i]).reduce((sum, value) => sum + value) / iteration
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment