The title is also from the front-end engineer Pen questions. Title Description:
Now there is a string that you want to perform n operations on the string, giving two numbers per operation: (P, L) a substring of l that starts with the character from Subscript p in the current string. You're going to flip this substring around and plug it right behind the substring's original position, and ask what the last string is. The subscript for a string is 0-based.
Idea: First get the substring about (p,l), get substring can use string.substring method. Then the inverse of the rotor string, there is no reversal method, but the array has, so you can first convert the string into an array, reversed and then converted to a string. Finally, the inverted substring is inserted after the original substring. The implementation of inserting strings into the original string at a specific location, the string does not have a ready-made method, the two methods, 1 is can use Substr,slice and other methods to first split the string and then in the connection. 2 is to use the splice method of the array, first convert the string to an array, and then use the Solice method to insert the element at the specified position and then into the string.
varinput = "ab\n2\n0 2\n1 3"; functionReverscon (input) {Input_array= Input.split ("\ n"); varNLine = 0; while(NLine <input_array.length) { varline = input_array[nline++].trim (); if(line = = = "){ Continue; } vars =Line ; varn = +input_array[nline++]; while(n--){ varInput_arrays = Input_array[nline++].trim (). Split ('); varp = +input_arrays[0]; varL = +input_arrays[1]; //Your code varsubstring = s.substring (p,p+l); Substring= Substring.split ("). Reverse (). Join ('); varArrs = S.split (");//This step requires a variable to save the result, because splice returns theArrs.splice (p+l,0,substring);//The characters are removed, so the ligatures will return emptys = Arrs.join (");//Abbaabb}} console.log (s); }; Reverscon (input);
JavaScript implements Palindrome decoding