41
loading...
This website collects cookies to deliver better user experience
function remove(arr) {
}
console.log(remove([1, 2, 3, 1, 2, 3], 2, 3));
function remove(arr) {
let args = [...arguments];
args.splice(0, 1)
return arr.filter(function(num) {
if (args.indexOf(num) === -1 ) {
return num;
}
})
}
(remove([1, 2, 3, 1, 2, 3], 2, 3)); // when console.log it will display [1, 1];
function fix(str) {
return str;
}
fix('Check Out My Rank');
function fix(str) {
let regexStr = str.replace(/([a-z])([A-Z])/g, "$1 $2");
let spacesOr = regexStr.replace(/\s|_/g, "-");
return spacesOr.toLowerCase();
}
console.log(fix('Check Out My Rank')); will display check-out-my-rank
function changeIntoPigLatin(str) {
return str;
}
changeIntoPigLatin("algorithm");
function changeIntoPigLatin(str) {
let vowel = str.match(/[aeiou]/); // we don't use g (global)
let firstPosition = str.indexOf(vowel);
if (firstPosition > 0) {
return str.slice(firstPosition) + str.slice(0, firstPosition) + "ay";
} else if (str.indexOf(vowel) === -1) {
return str + "ay"
}
return str + "way";
};
console.log(changeIntoPigLatin("algorithm")); // will display algorithmway
Games
with the word movies
, it should be replaced as Movies
.
Problem:
function myReplace(str, before, after) {
return str;
}
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
function myReplace(str, before, after) {
if (before[0] === before[0].toUpperCase()) {
after = after[0].toUpperCase() + after.slice(1);
} else if (before[0] === before[0].toLowerCase()) {
after = after[0].toLowerCase() + after.slice(1);
}
return str.replace(before , after)
}
console.log(myReplace("He is Sleeping on the couch", "Sleeping", "sitting")); // will display He is Sitting on the couch