Write a function that removes the spaces from the string, then return the resultant string.
Examples:
Input -> Output
"8 j 8 mBliB8g imjB8B8 jl B" -> "8j8mBliB8gimjB8B8jlB"
"8 8 Bi fk8h B 8 BB8B B B B888 c hl8 BhB fd" -> "88Bifk8hB8BB8BBBB888chl8BhBfd"
"8aaaaa dddd r " -> "8aaaaaddddr"
function noSpace(x){
return x.split(" ").join('')
}
function noSpace(x){
return x.replace(/\s/g, '');
}
function noSpace(x){return x.split(' ').join('')}
Messi is a soccer player with goals in three leagues:
Complete the function to return his total number of goals in all three leagues.
Note: the input will always be valid.
For example:
5, 10, 2 --> 17
function goals (laLigaGoals, copaDelReyGoals, championsLeagueGoals) {
return laLigaGoals + copaDelReyGoals + championsLeagueGoals
}
const goals = (...a) => a.reduce((s, v) => s + v, 0);
const goals = (a,b,c) => a + b + c;
Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained.
"This is an example!" ==> "sihT si na !elpmaxe"
"double spaces" ==> "elbuod secaps"
function reverseWords(str) {
const words = str.split(" ");
const newWord = words.map((item)=>{
return item.split("").reverse().join("")
})
return newWord.join(" ")
}
function reverseWords(str) {
return str.split(' ').map(function(word){
return word.split('').reverse().join('');
}).join(' ');
}
function reverseWords(str) {
// Go for it
//split words into seperate arrays
return str.split("").reverse().join("").split(" ").reverse().join(" ");
}
function reverseWords(str) {
return str.split(' ').map( str => str.split('').reverse().join('') ).join(' ');
}