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>`}
|
||||
* ${`<img src="/bogus/path" onerror="alert('xss')">`}
|
||||
* </strong>`
|
||||
*
|
||||
* // DocumentFragment
|
||||
* // └─ strong
|
||||
* // ├─ em
|
||||
|
||||
+13
-13
@@ -9,17 +9,6 @@ export type Tuple<
|
||||
R extends readonly T[] = [],
|
||||
> = 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.
|
||||
* @author MindfulMinun
|
||||
@@ -61,7 +50,7 @@ export function* limit<T>(count: number, iterable: Iterable<T>) {
|
||||
i++
|
||||
} else break
|
||||
}
|
||||
return iterable
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +66,7 @@ export async function* limitAsync<T>(count: number, iterable: AsyncIterable<T>)
|
||||
i++
|
||||
} 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]
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* *in place*, meaning the original array is modified.
|
||||
|
||||
@@ -66,6 +66,8 @@ function _isPrime(n: number) {
|
||||
|
||||
/**
|
||||
* Verify if a given number is prime.
|
||||
* @author MindfulMinun
|
||||
* @since 2022-10-13
|
||||
*/
|
||||
export function isPrime(n: number): boolean {
|
||||
// To verify if a number is prime, we only need to check if it is divisible by
|
||||
|
||||
Reference in new issue
Block a user