将字符串使用空格进行连接
createMessage("Hello")("World!")("how")("are")("you?")() === "Hello World! how are you?"
function createMessage(str) {
return function(next){
if (next === undefined) {return str;}
return createMessage(str + " "+ next);
}
}
## 遍历b来除去a中相同的
function array_diff(a, b) {
b.map(function(item){
if(a.indexOf(item)!=-1){
while(a.indexOf(item)!=a.lastIndexOf(item)){
a.splice(a.indexOf(item),1)
}
a.splice(a.indexOf(item),1)}
})
return a
}
## 之间遍历a
function array_diff(a, b) {
return a.filter(function(x) { return b.indexOf(x) == -1; });
}
domainName("http://github.com/carbonfive/raygun") == "github"
domainName("http://www.zombie-bites.com") == "zombie-bites"
domainName("https://www.cnet.com") == "cnet"
function domainName(url){
return url.replace(/(https?:\/\/)?(www\.)?/,"").split("/")[0].split("\.")[0]
}