Repository: discordjs/discord.js
File: packages/collection/src/collection.ts (TypeScript)

Code before:
	public lastKey(amount: number): Key[];
	public lastKey(amount?: number): Key | Key[] | undefined {
		if (amount === undefined) return this.keyAt(-1);
		if (!amount) return [];
		if (amount < 0) return this.firstKey(amount * -1);
		const arr = [...this.keys()];
		return arr.slice(amount * -1);
	}

	/**
	 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
	 * Returns the item at a given index, allowing for positive and negative integers.
	 * Negative integers count back from the last item in the collection.
	 *
	 * @param index - The index of the element to obtain
	 */
	public at(index: number): Value | undefined {
		index = Math.trunc(index);
		if (index >= 0) {
			if (index >= this.size) return undefined;
		} else {
			if (index < this.size * -1) return undefined;
			index += this.size;
		}

		const iter = this.values();
		for (let skip = 0; skip < index; skip++) {
			iter.next();
		}

		return iter.next().value!;
	}

	/**
	 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
	 * Returns the key at a given index, allowing for positive and negative integers.
	 * Negative integers count back from the last item in the collection.
	 *
	 * @param index - The index of the key to obtain
	 */
	public keyAt(index: number): Key | undefined {
		index = Math.trunc(index);
		if (index >= 0) {
			if (index >= this.size) return undefined;
		} else {
			if (index < this.size * -1) return undefined;
			index += this.size;
		}

		const iter = this.keys();
		for (let skip = 0; skip < index; skip++) {

Review comment (suggestion):
Better readability
```suggestion
		if (index < 0) {
			index += this.size;
			if (index < 0) return undefined;
		} else if (index >= this.size) {
			return undefined;
		}
```

Code after:
	public lastKey(): Key | undefined;
	public lastKey(amount: number): Key[];
	public lastKey(amount?: number): Key | Key[] | undefined {
		if (amount === undefined) return this.keyAt(-1);
		if (!amount) return [];
		if (amount < 0) return this.firstKey(amount * -1);

		const arr = [...this.keys()];
		return arr.slice(amount * -1);
	}

	/**
	 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
	 * Returns the item at a given index, allowing for positive and negative integers.
	 * Negative integers count back from the last item in the collection.
	 *
	 * @param index - The index of the element to obtain
	 */
	public at(index: number): Value | undefined {
		index = Math.trunc(index);
		if (index >= 0) {
			if (index >= this.size) return undefined;
		} else {
			index += this.size;
			if (index < 0) return undefined;
		}

		const iter = this.values();
		for (let skip = 0; skip < index; skip++) {
			iter.next();
		}

		return iter.next().value!;
	}

	/**
	 * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.
	 * Returns the key at a given index, allowing for positive and negative integers.
	 * Negative integers count back from the last item in the collection.
	 *
	 * @param index - The index of the key to obtain
	 */
	public keyAt(index: number): Key | undefined {
		index = Math.trunc(index);
		if (index >= 0) {
			if (index >= this.size) return undefined;
		} else {
			index += this.size;
			if (index < 0) return undefined;
		}