[20221111] 함수의 매개변수
오늘 배운 것 spread operator: function 함수이름 (...매개변수)를 통해, 요소의 나열만으로 함수 내에서 arry로 받아올 수 있음 function findMin(...arr) { console.log(arr); // [ 100, 40, 6, 2, 90, 180 ] let output = arr[0]; for (const item of arr) { if (output > item) { output = item; } } return console.log(output); // 2 } findMin(100, 40, 6, 2, 90, 180); // 아래는 앞의 숫자는 각각의 개별 매개변수로 받아오고, 나머지를 배열로 받아 옴 function findMin(a, b, ...arr) { co..
[20221110] recursion으로 merge sort 구현
Merge Sort는 배열을 하나의 요소가 개별 배열이 될때까지 쪼개고, 쪼개진 배열 두개씩 값을 비교하여 merge sort하는 알고리즘이다. [8, 7, 3, 2] [8, 7] [3, 2] [8] [7] [3] [2] [7, 8] [2, 3] [2, 3, 7 8] 아래 사이트를 참고하면 시각적인 이해를 돕는다. https://visualgo.net/en/sorting Sorting (Bubble, Selection, Insertion, Merge, Quick, Counting, Radix) - VisuAlgo VisuAlgo is free of charge for Computer Science community on earth. If you like VisuAlgo, the only "payment"..