Skip to content

Instantly share code, notes, and snippets.

@ctkqiang
Created February 11, 2025 11:24
Show Gist options
  • Save ctkqiang/f45ef63746674c974cb4ef21b0fd9da7 to your computer and use it in GitHub Desktop.
Save ctkqiang/f45ef63746674c974cb4ef21b0fd9da7 to your computer and use it in GitHub Desktop.

Revisions

  1. ctkqiang created this gist Feb 11, 2025.
    46 changes: 46 additions & 0 deletions interview_use.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    // For Javascript I use (commonJS)

    const swapNumber = (a, b) => {
    let temp = a;

    a = b;
    b = temp;


    return [a, b];
    };

    // Execution:

    const num1 = 20;
    const num2 = 30;

    [num1, num2] = swapNumber(num1, num2);

    console.log(num1);
    console.log(num2);

    // ----------


    // My ans for php


    function swapNumber($a, $b) {
    $temp = $a;
    $a = $b;
    $b = $temp;


    return array($a, $b);
    }

    // Call func

    $a = 20;
    $b = 30;

    list($firstNum, $secondNum) = swapNumber($firstNum, $secondNum);

    echo $firstNum."\n";
    echo $secondNum;