Apply Functional Programming to Convert Strings

Apply Functional Programming to Convert Strings
0.0 0

#1

Hello, i cant understand why didnt my code pass tests. Can you help me understand)

/ the global variable
var globalTitle = “Winter Is Coming”;

// Add your code below this line
function urlSlug(title) {
var arr=title.split(/\s+/);
for (let i=0;i<arr.length;i++) {
arr[i]=arr[i].toLowerCase();
}
return arr.join("-");

}
// Add your code above this line

var winterComing = urlSlug(globalTitle); // Should be “winter-is-coming”
console.log(winterComing);


#2

Hi @Timazver

It’s because your failing the test case:

urlSlug(" Winter Is Coming") should return "winter-is-coming".

Also, you should really be using functional programming to solve this challenge, reduce, map, filter etc…


#3

Thank you for your reply. But i execute my code in my PC and it works good)