This question is really a pain.
I tried with javascript, the multiassign doesn't work, at least in chrome. I solved it with the deconstruct operator:
let a = 1; let b = 2; [a,b] = [b,a];
It does the trick, but knowing how to do this in an interview wouldn't be my main concern if i was the interviewer.
This solution looks good, but it doesn't qualify for the requirements, because you create a temporary array [b,a] in the third line.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This question is really a pain.
I tried with javascript, the multiassign doesn't work, at least in chrome.
I solved it with the deconstruct operator:
It does the trick, but knowing how to do this in an interview wouldn't be my main concern if i was the interviewer.
This solution looks good, but it doesn't qualify for the requirements, because you create a temporary array [b,a] in the third line.