The reshape(n, str) method should return the string str without spaces and layed outin lines of at most n characters.Examples:CallReturned Stringreshape(3, "abc defghij")abcdefghijreshape (2, 1 23 456 )123456Write the body of the reshape(n, str) method.Note: Do not add a trailing \n character.
Answers
Answered by
0
Explanation:
sbsbbd sxnx bsbsbbshzhhsgvw
Answered by
0
To Find:
We need to rebuild the "reshape(n, str)" function or method.
Solution:
This code has been written in Java.
function reshape(string, num) {
var regex = new RegExp(".{" + num + "}", "g");
return string.replace(regex,"$&\n");
}
console.log(reshape("blablabla", 3));
In this code, a function has been made naming reshape and two attributes have been included, one for the string and another for dividing the string.
The output of the above will be:
bla
bla
bla
Regex is the short form of the regular expression. It helps to generate different types of patterns based on a particular string.
Thus, all conditions are getting fulfilled with this type of method formation.
#SPJ3
Similar questions