1/**2* @param {string} s3* @param {number} k4* @return {string}5*/6var orderlyQueue = function (s, k) {7// rotate the string one by one, and check which is lexographically smaller8if (k === 1) {9let temp = `${s}`;10let smallest = `${s}`;11let count = 0;12while (count < s.length) {13temp = temp.substring(1, s.length) + temp.charAt(0);14if (temp < smallest) {15smallest = temp;16}17count++;18}19return smallest;20}2122// if k is greater than 1, any permutation is possilbe23// so we simply return the sorted string (convert to array -> sort -> back to string)24if (k > 1) {25return [...s].sort().join("");26}2728return s;29};