Hey guys, how come using "" is optional in reverse() but required in join() and split()? Also is there a situation where it should not be used?
Thanks
Your code so far
function reverseString(str) {
var splitString = str.split("");
var reverseArray = splitString.reverse();
var combinedString = reverseArray.join("");
return combinedString;
}
console.log(reverseString("Greetings from Earth"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.
Hey guys, how come using "" is optional in reverse() but required in join() and split() ? Also is there a situation where it should not be used?
Because for join it has to know what character you want to go in between the joined pieces (in this case nothing). And split needs to know what character you want to split on (in this case an empty string is given so it means to split for everything, as much as you can). Try some other values and see what happens.
For reverse, it doesn’t need any other data - to reverse is to reverse.