Versions

  • v0

    11/9/2024
    Open: Version
    +39
    -0


    export async function val_PJEj4CadkM(req) {
    try {
    // Execute the code directly and capture its result
    const result = await (async () => {
    const calculatePi = (iterations) => {
    let pi = 0;
    let divisor = 1;
    for (let i = 0; i < iterations; i++) {
    pi += (i % 2 === 0 ? 1 : -1) / divisor;
    divisor += 2;
    }
    return pi * 4;
    };

    return calculatePi(1000000);
    })();

    // Return the result in a properly formatted response
    return new Response(JSON.stringify({
    result: result,
    type: typeof result
    }), {
    headers: { 'Content-Type': 'application/json' }
    });
    } catch (error) {
    return new Response(JSON.stringify({
    error: {
    message: error.message,
    stack: error.stack,
    type: error.name
    }
    }), {
    status: 500,
    headers: { 'Content-Type': 'application/json' }
    });
1
Next
dhvanil-val_pjej4cadkm.web.val.run
Updated: November 9, 2024