// 1. Arrays: Implementiere die folgenden Funktionen
export function squareNumbers(numbers: number[]): number[] {
  return numbers.map((num) => num * num);
}

export function filterEvenNumbers(numbers: number[]): number[] {
  return numbers.filter((num) => num % 2 === 0);
}

export function sumNumbers(numbers: number[]): number {
  return numbers.reduce((acc, num) => acc + num, 0);
}

export function findFirstGreaterThan(
  numbers: number[],
  limit: number
): number | undefined {
  return numbers.find((num) => num > limit);
}

export function sortNumbersDescending(numbers: number[]): number[] {
  return [...numbers].sort((a, b) => b - a);
}

export function sliceNumbers(
  numbers: number[],
  start: number,
  end: number
): number[] {
  return numbers.slice(start, end);
}

export function modifyArray(
  numbers: number[],
  index: number,
  newValue: number
): number[] {
  const modified = [...numbers];
  modified.splice(index, 1, newValue);
  return modified;
}

// 2. Maps: Implementiere die folgenden Funktionen
export function createUserMap(): Map<number, string> {
  return new Map([
    [1, 'Alice'],
    [2, 'Bob'],
  ]);
}

export function getUserById(
  users: Map<number, string>,
  id: number
): string | undefined {
  return users.get(id);
}

export function getAllUserIds(users: Map<number, string>): number[] {
  return Array.from(users.keys());
}

export function getAllUserNames(users: Map<number, string>): string[] {
  return Array.from(users.values());
}

// 3. Sets: Implementiere die folgenden Funktionen
export function createUniqueNumberSet(numbers: number[]): Set<number> {
  return new Set(numbers);
}

export function isNumberInSet(set: Set<number>, value: number): boolean {
  return set.has(value);
}

export function convertSetToArray(set: Set<number>): number[] {
  return Array.from(set);
}
