Path: blob/main/extensions/copilot/test/simulation/fixtures/edit/3575.ts
13399 views
/**1* Returns the intersection of two arrays as a new array.2* The intersection includes the elements that are common to both input arrays.3* The function avoids duplicates by deleting each found element from the set.4*5* @param arr1 - The first input array.6* @param arr2 - The second input array.7* @returns A new array containing the intersection of the input arrays.8*/9export function arrayIntersection(arr1: number[], arr2: number[]): number[] {10const set = new Set(arr1);11const result: number[] = [];12for (let num of arr2) {13if (set.has(num)) {14result.push(num);15set.delete(num); // Avoid duplicates16}17}18return result;19}2021/**22* This function finds and logs all pairs of numbers from two arrays that add up to a given sum.23*24* @param arr1 - The first array of numbers.25* @param arr2 - The second array of numbers.26* @param sum - The target sum. If not provided, defaults to 10.27*/28export function findPairs(arr1: number[], arr2: number[], sum: number = 10): void {29for (let i = 0; i < arr1.length; i++) {30for (let j = 0; j < arr2.length; j++) {31if (arr1[i] + arr2[j] === sum) {32console.log(`Pair: (${arr1[i]}, ${arr2[j]})`);33}34}35}36}3738/**39* Sorts an array of numbers in ascending order using the Bubble Sort algorithm.40*41* @param arr - The array of numbers to be sorted.42* @returns The sorted array of numbers.43*/44export function sort(arr: number[]): number[] {45let len = arr.length;46for (let i = 0; i < len; i++) {47for (let j = 0; j < len - i - 1; j++) {48if (arr[j] > arr[j + 1]) {49[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];50}51}52}53return arr;54}5556