Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
retraigo committed Jul 4, 2022
1 parent 63e669c commit 5a2560e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class BetterMap<K, V> extends Map<K, V> {
first(): V | undefined;
first(n: number): V[];
first(n?: number): V | V[] | undefined {
if(n && n < 0) return this.last(-n)
const iter = this.values();
if (n && n > this.size) return;
return (typeof n === "number" && !isNaN(n))
Expand All @@ -104,9 +105,10 @@ export class BetterMap<K, V> extends Map<K, V> {
* @param {number} n Number of elements to fetch.
* @returns The first element's key / undefined.
*/
firstKey(): V | undefined;
firstKey(n: number): V[];
firstKey(n?: number): V | V[] | undefined {
firstKey(): K | undefined;
firstKey(n: number): K[];
firstKey(n?: number): K | K[] | undefined {
if(n && n < 0) return this.firstKey(-n)
const iter = this.keys();
if (n && n > this.size) return;
return (typeof n === "number" && !isNaN(n))
Expand Down Expand Up @@ -147,6 +149,7 @@ export class BetterMap<K, V> extends Map<K, V> {
last(): V | undefined;
last(n: number): V[];
last(n?: number): V | V[] | undefined {
if(n && n < 0) return this.first(-n)
const arr = this.array();
return (typeof n === "number" && !isNaN(n))
? arr.slice(-n)
Expand All @@ -158,6 +161,7 @@ export class BetterMap<K, V> extends Map<K, V> {
lastKey(): K | undefined;
lastKey(n: number): K[];
lastKey(n?: number): K | K[] | undefined {
if(n && n < 0) return this.firstKey(-n)
const arr = this.array(true);
return (typeof n === "number" && !isNaN(n))
? arr.slice(-n)
Expand Down

0 comments on commit 5a2560e

Please sign in to comment.