/// import { recipe, UI } from "commontools"; interface State { a: number; b: number; price: number; text: string; values: number[]; name: string; float: string; } export default recipe("FunctionCalls", (state) => { return { [UI]: (

Math Functions

Max: {Math.max(state.a, state.b)}

Min: {Math.min(state.a, 10)}

Abs: {Math.abs(state.a - state.b)}

Round: {Math.round(state.price)}

Floor: {Math.floor(state.price)}

Ceiling: {Math.ceil(state.price)}

Square root: {Math.sqrt(state.a)}

String Methods as Function Calls

Uppercase: {state.name.toUpperCase()}

Lowercase: {state.name.toLowerCase()}

Substring: {state.text.substring(0, 5)}

Replace: {state.text.replace("old", "new")}

Includes: {state.text.includes("test") ? "Yes" : "No"}

Starts with: {state.name.startsWith("A") ? "Yes" : "No"}

Number Methods

To Fixed: {state.price.toFixed(2)}

To Precision: {state.price.toPrecision(4)}

Parse Functions

Parse Int: {parseInt(state.float)}

Parse Float: {parseFloat(state.float)}

Array Method Calls

Sum: {state.values.reduce((a, b) => a + b, 0)}

Max value: {Math.max(...state.values)}

Joined: {state.values.join(", ")}

Complex Function Calls

Multiple args: {Math.pow(state.a, 2)}

Nested calls: {Math.round(Math.sqrt(state.a))}

Chained calls: {state.name.trim().toUpperCase()}

With expressions: {Math.max(state.a + 1, state.b * 2)}

), }; });