Skip to content

Instantly share code, notes, and snippets.

@amalrkc
Last active August 22, 2025 16:19
Show Gist options
  • Select an option

  • Save amalrkc/09f814002bbd0c49ba697fe75982d9c0 to your computer and use it in GitHub Desktop.

Select an option

Save amalrkc/09f814002bbd0c49ba697fe75982d9c0 to your computer and use it in GitHub Desktop.
Exchange values among two functions JS problem QA round

Problem

Declare two variables in function A, bring them to function B, then bring them back to function A

Solution

let funcA = (x = 0, y = 1) => {
    console.log(`funcA`,x, y)
    return [x, y];
}

let funcB = () => {
    let [x, y] = funcA();
    console.log(`funcB`,x,y);
    funcA(x, y)
}

funcB();

Old solution

let funcA = (values) => {
    console.log(`funcA values recieved: `, values)
    if(values && values.length) {
        console.log(`funcA returning`, values, `\n`)
        return values;
    }
    let x = 0;
    let y = 1;
    console.log(`funcA returning`, [x, y], `\n`)
    return [x, y];
}

let funcB = (values) => {
    console.log(`funcB: `, values, `\n`)
	return values;
}

console.log(
	funcA(funcB(funcA()))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment