Swap Two Values (No Extra Variable)
JavaScript
Easy
5 views
Problem Description
You are given two values a and b. Swap them and print the swapped values. Use JavaScript style swap (no third variable).
Input Format
One line: a b (space separated).
Output Format
One line: swapped_a swapped_b.
Constraints
a and b are integers in range -1e9 to 1e9.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s){process.exit(0);}let [a,b]=s.split(/\s+/).map(Number);[a,b]=[b,a];process.stdout.write(a+' '+b);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!