43 lines
891 B
TypeScript
43 lines
891 B
TypeScript
import { Request } from "firebase-functions";
|
|
|
|
class Utils {
|
|
static parseInput(request: Request): string[] {
|
|
|
|
const body = request.body;
|
|
if (typeof body === "string") {
|
|
return body.split("\n");
|
|
} else if (body.constructor === Array) {
|
|
return body;
|
|
} else {
|
|
throw Error("Invalid request");
|
|
}
|
|
}
|
|
|
|
static sum(values: number[]): number {
|
|
return values.reduce((a, b) => a + b);
|
|
}
|
|
|
|
static bigSum(values: bigint[]): bigint {
|
|
return values.reduce((a, b) => a + b);
|
|
}
|
|
|
|
static bigMax(values: bigint[]): bigint {
|
|
return values.reduce((a, b) => a > b ? a : b);
|
|
}
|
|
|
|
static bigMin(values: bigint[]): bigint {
|
|
return values.reduce((a, b) => a < b ? a : b);
|
|
}
|
|
|
|
static zeroes(length: number): number[] {
|
|
|
|
const res = [];
|
|
for (let i = 0; i < length; i++) {
|
|
res.push(0);
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
|
|
export default Utils;
|