Count array / list occurrences... 😐
const arr = Array.from(
{ length: 10 },
() => Math.round(Math.random() * 5)
);
countOf(3, arr);
// {second}.{millisecond} | |
// {minute}:{second}.{millisecond} | |
// {hour}:{...} | |
const unitScale = [ | |
1000 /* millsecond -> second */, | |
60 /* second -> minute */, | |
60 /* minute -> hour */, | |
24 /* hour -> day */, | |
7 /* day -> week */ |
// https://stackoverflow.com/a/19277804 | |
function getFurthestFrom(target: number, list: number[]) { | |
const outcome: string[] = []; | |
let record = 0; | |
for (const index in list) { | |
const entry = list[index]; | |
const distance = Math.abs(entry - target); | |
if (distance === record) { |
export class YearRange { | |
static testPattern = /[\d -,]+/g; | |
static splitPattern = / *[-,] */g; | |
private static getContext(input: string): YearRangeContext { | |
console.assert(this.testPattern.test(input), 'Invalid pattern match'); | |
const fragments = input.split(this.splitPattern); | |
const symbols = input.match(this.splitPattern) ?? []; |
using System; | |
using System.Collections.Generic; | |
namespace RoleDistribution | |
{ | |
public struct Role { | |
// type decimal can be exchanged for double or float with their respective unit conversion, the outcome will not change | |
public Role(string name, decimal ratio) { | |
Name = name; | |
Ratio = ratio; |
import { ComponentContext, SlashCreator } from "slash-create"; | |
export default class ComponentWildcard { | |
cache: Map<string, { | |
eventKeys: string[], | |
id: string, | |
callback: WildcardCallback | |
}> = new Map(); | |
constructor(public creator: SlashCreator) { |
const { Client } = require("discord.js"); | |
const { GatewayServer, SlashCreator, Command, CommandOptionType, InteractionResponseFlags } = require("slash-create"); | |
const { Endpoints } = require("slash-create/lib/constants"); | |
const client = new Client(); | |
const creator = new SlashCreator({ | |
applicationID: "APP_ID", | |
publicKey: "PUBLIC_KEY", |
Also noted when hovering over the taskbar applet.
Requires activation before use.
import duration from "./duration-functions.js"; | |
for (const unit of Object.keys(duration)) { | |
Number[unit] = function (n) { | |
return Number(n)[unit](); | |
} | |
Number.prototype[unit] = function () { | |
return duration[unit](this); | |
} |