I have a unique challenge where I can only post once every 90 minutes, so here's my double question. First up, I need to create a function that can replace a specific character in a string with a space.
//====================== EXAMPLE ========================
var str = "I,Really,Like,Pizza";
characterRemover(str, ",");
"I Really Like Pizza"; // <====== EXPECTED OUTPUT
//=========================================================
After trying out this code, I encountered a problem where the function didn't work as expected.
function chracterRemover(str, cha){
var replaced = str.split('cha').join(' ');
return replaced;
}
Instead of replacing the character with a space, it returned the same string.
The second part of my question involves creating a function that can determine if the input data type is an array or not.
//====================== EXAMPLE ========================
var one = { name: "antonello" };
false; // <====== EXPECTED OUTPUT
var two = ["name", "antonello"];
true; // <====== EXPECTED OUTPUT
var three = [[], [], {}, "antonello", 3, function() {}];
true; // <====== EXPECTED OUTPUT
//=========================================================
For this part, I attempted the following function.
function isArrayFun(array){
if {
typeof array = 'array';
return "Array";
} else {
return "Not an array"
}
}
However, my code resulted in an error message:
Uncaught SyntaxError: Unexpected token '{'
I'm not sure why this error occurred. Any help will be greatly appreciated. Thank you!