# tips

{% tabs %}
{% tab title="🔴 主題" %}
* [fill-2d-array](tips/fill-2d-array "mention")
* [iife](val/func/expr/iife "mention")
* [arr.containssubarray](val/builtin/arr/ext/arr.containssubarray "mention") - <mark style="color:yellow;">**closure**</mark> with <mark style="color:orange;">**internal parameter**</mark> ⭐️
{% endtab %}

{% tab title="💈範例" %}
```javascript
// filter using `thisArg`
const arr = [1,0,2,0,3,0,4,5,6,7,8,9,10,11,12,13,14];

// ⭐️ requires a normal function, doesn't work with arrow functions.
//                          ╭───  ⭐️  ───╮
const filtered = arr.filter(function(item) {
  if (this.count < 10 && item > 0) {          // ⭐️ this == thisArg
    this.count++;
    return true;
  }
  return false;
}, {count: 0});
// ╰── ⭐️ ──╯ <--- `thisArg`
```
{% endtab %}

{% tab title="🗣 討論" %}
* [JS - Get top 5 max elements from array](https://stackoverflow.com/questions/39254218/js-get-top-5-max-elements-from-array/39254328)
* [How to limit for 10 results the array.filter?](https://stackoverflow.com/a/56169001/5409815)
{% endtab %}
{% endtabs %}
