chore: Add date to isPrime, move choose
This commit is contained in:
3 files changed
+16
-13
No files matched your search
@@ -17,6 +17,7 @@ export { HTML_ESCAPES }
|
|||||||
* ${html`<em>Look ma, nested HTML!</em>`}
|
* ${html`<em>Look ma, nested HTML!</em>`}
|
||||||
* ${`<img src="/bogus/path" onerror="alert('xss')">`}
|
* ${`<img src="/bogus/path" onerror="alert('xss')">`}
|
||||||
* </strong>`
|
* </strong>`
|
||||||
|
*
|
||||||
* // DocumentFragment
|
* // DocumentFragment
|
||||||
* // └─ strong
|
* // └─ strong
|
||||||
* // ├─ em
|
* // ├─ em
|
||||||
|
|||||||
+13
-13
@@ -9,17 +9,6 @@ export type Tuple<
|
|||||||
R extends readonly T[] = [],
|
R extends readonly T[] = [],
|
||||||
> = R['length'] extends N ? R : Tuple<T, N, readonly [T, ...R]>;
|
> = R['length'] extends N ? R : Tuple<T, N, readonly [T, ...R]>;
|
||||||
|
|
||||||
/**
|
|
||||||
* Chooses a random element from an array
|
|
||||||
*
|
|
||||||
* choose(document.all).click()
|
|
||||||
* @since 2020-06-29
|
|
||||||
*/
|
|
||||||
export function choose<T>(arr: T[]): T {
|
|
||||||
if (!arr.length) throw new Error('Cannot choose from an empty array')
|
|
||||||
return arr[Math.floor(Math.random() * arr.length)]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an iterable that always yields the given value.
|
* Creates an iterable that always yields the given value.
|
||||||
* @author MindfulMinun
|
* @author MindfulMinun
|
||||||
@@ -61,7 +50,7 @@ export function* limit<T>(count: number, iterable: Iterable<T>) {
|
|||||||
i++
|
i++
|
||||||
} else break
|
} else break
|
||||||
}
|
}
|
||||||
return iterable
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,7 +66,7 @@ export async function* limitAsync<T>(count: number, iterable: AsyncIterable<T>)
|
|||||||
i++
|
i++
|
||||||
} else break
|
} else break
|
||||||
}
|
}
|
||||||
return iterable
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +107,17 @@ export function divide<T>(list: T[], predicate: (this: typeof list, value: T, in
|
|||||||
return [pass, fail]
|
return [pass, fail]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chooses a random element from an array
|
||||||
|
*
|
||||||
|
* choose(document.all).click()
|
||||||
|
* @since 2020-06-29
|
||||||
|
*/
|
||||||
|
export function choose<T>(arr: T[]): T {
|
||||||
|
if (!arr.length) throw new Error('Cannot choose from an empty array')
|
||||||
|
return arr[Math.floor(Math.random() * arr.length)]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shuffles an array. Note that this function swaps the elements
|
* Shuffles an array. Note that this function swaps the elements
|
||||||
* *in place*, meaning the original array is modified.
|
* *in place*, meaning the original array is modified.
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ function _isPrime(n: number) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if a given number is prime.
|
* Verify if a given number is prime.
|
||||||
|
* @author MindfulMinun
|
||||||
|
* @since 2022-10-13
|
||||||
*/
|
*/
|
||||||
export function isPrime(n: number): boolean {
|
export function isPrime(n: number): boolean {
|
||||||
// To verify if a number is prime, we only need to check if it is divisible by
|
// To verify if a number is prime, we only need to check if it is divisible by
|
||||||
|
|||||||
Reference in new issue
Block a user