This is a double question because I can just post once every 90 minutes. First I have to write a function that replaces a character of a string.
JavaScript
x
6
1
//====================== EXAMPLE ========================
2
var str = "I,Really,Like,Pizza";
3
characterRemover(str, ",");
4
"I Really Like Pizza"; // <====== EXPECTED OUTPUT
5
//=========================================================
6
And puts a space in place of the chosen character. I tried this but is not working.
JavaScript
1
5
1
function chracterRemover(str, cha){
2
var replaced = str.split('cha').join(' ');
3
return replaced;
4
}
5
It returns just the same string.
And the second thing is that I have to write a function that returns true if the data type introduced is an arrat and false for the rest.
JavaScript
1
9
1
//====================== EXAMPLE ========================
2
var one = { name: "antonello" };
3
false; // <====== EXPECTED OUTPUT
4
var two = ["name", "antonello"];
5
true; // <====== EXPECTED OUTPUT
6
var three = [[], [], {}, "antonello", 3, function() {}];
7
true; // <====== EXPECTED OUTPUT
8
//=========================================================
9
I’ve tried this.
JavaScript
1
9
1
function isArrayFun(array){
2
if {
3
typeof array = 'array';
4
return "Array";
5
} else {
6
return "Not an array"
7
}
8
}
9
But as well, it doesnt work.
I get this error:
JavaScript
1
2
1
Uncaught SyntaxError: Unexpected token '{'
2
I don’t know why. Thanks in advance for the help.
Advertisement
Answer
JavaScript
1
3
1
// First One
2
const str = "I,Really,Like,Pizza";
3
console.log(str.split(',').join(' '));
JavaScript
1
13
13
1
// Second One
2
function isArrayFun(array){
3
return Array.isArray(array);
4
}
5
6
const one = { name: "antonello" };
7
console.log(isArrayFun(one));
8
9
const two = ["name", "antonello"];
10
console.log(isArrayFun(two));
11
12
const three = [[], [], {}, "antonello", 3, function() {}];
13
console.log(isArrayFun(three));