Check if string is rotated by two places

Given two strings, str1 and str2, check if str2 can be obtained by rotating str1 exactly 2 places in either a clockwise or anticlockwise direction.

Hint

Rotate the string 1. Clockwise: Move frist two characters in string 1 to the end. Anticlockwise: Move last two characters in string 1 to the front. Check if either of the rotated versions of string 1 matches string 2 exactly.

# Python implementation
str1 = "river"
str2 = "verri"
l = len(str1)

r1 = str1[2:] + str1[0:2]
r2 = str1[-2:] + str1[0:-2]

print(r1 == str2 or r2 == str2)
// Javascript implementation
const str1 = "river";
const str2 = "verri";
const len = str1.length;

const r1 = str1.slice(2) + str1.slice(0, 2);
const r2 = str1.slice(len - 2) + str1.slice(0, len - 2);

console.log(r1 === str2 || r2 === str2);