Open this example in the interactive library
Source code
const rotate = ([x, y], r) => [
x * Math.cos(r) - y * Math.sin(r),
x * Math.sin(r) + y * Math.cos(r),
];
console.log(rotate([2, 0], Math.PI / 2).map(Math.round));
Sample output
[ 0, 2 ]

Open this example in the interactive library
const rotate = ([x, y], r) => [
x * Math.cos(r) - y * Math.sin(r),
x * Math.sin(r) + y * Math.cos(r),
];
console.log(rotate([2, 0], Math.PI / 2).map(Math.round));
[ 0, 2 ]