# 6kyu

## 函数的连续调用

> 将字符串使用空格进行连接
>
> createMessage("Hello")("World!")("how")("are")("you?")() === "Hello World! how are you?"

函数中返回一个匿名函数，匿名函数调用父函数实现层级的调用，感觉类似递归的思想

```javascript
function createMessage(str) {
    return function(next){
      if (next === undefined) {return str;}
      return createMessage(str + " "+ next);
    }
}
```

## 两个数组去重

```javascript
## 遍历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
}
```

秀儿

```javascript
## 之间遍历a
function array_diff(a, b) {
  return a.filter(function(x) { return b.indexOf(x) == -1; });
}
```

## 检测网址的主域名

输入数据如下,这次我也成为了秀儿的一员 hh

```javascript
domainName("http://github.com/carbonfive/raygun") == "github" 
domainName("http://www.zombie-bites.com") == "zombie-bites"
domainName("https://www.cnet.com") == "cnet"
```

```javascript
function domainName(url){
  return url.replace(/(https?:\/\/)?(www\.)?/,"").split("/")[0].split("\.")[0]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zpliu.gitbook.io/booknote/qian-duan-cao-zuo/javascript/6kyu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
