Skip to content

Instantly share code, notes, and snippets.

@ambrizals
Created September 12, 2022 10:02
Show Gist options
  • Save ambrizals/8cce40196b5cf30e5e4b2562cc75e1a9 to your computer and use it in GitHub Desktop.
Save ambrizals/8cce40196b5cf30e5e4b2562cc75e1a9 to your computer and use it in GitHub Desktop.
Nyoba buat formula di typescript
import { run } from "formula";
enum RumusType {
OPERATOR,
VARIABLE,
FIXEDVALUE,
}
interface Rumus {
urutan: number;
exp: string;
description: string;
type: RumusType;
}
const rumus: Rumus[] = [
{
urutan: 1,
exp: "keliling",
description: "Ukuran keliling benda",
type: RumusType.VARIABLE,
},
{
urutan: 2,
exp: "*",
description: "Kali",
type: RumusType.OPERATOR,
},
{
urutan: 3,
exp: "1500000",
description: "Nilai harga per meter keliling",
type: RumusType.FIXEDVALUE,
},
];
const injectFormula = (rumus: Rumus[]) => {
let formula: string = "";
for (const rms of rumus) {
formula = formula + rms.exp;
}
return formula;
};
const result = run(injectFormula(rumus), { keliling: 2 });
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment