Baseline 2025
Newly available
take()
㯠Iterator
ã¤ã³ã¹ã¿ã³ã¹ã®ã¡ã½ããã§ããã®ã¤ãã¬ã¼ã¿ã¼å
ã§æå®ãããæ°ã®è¦ç´ ãçæãããã®å¾çµäºããæ°ããã¤ãã¬ã¼ã¿ã¼ãã«ãã¼ãªãã¸ã§ã¯ããè¿ãã¾ãã
limit
å復å¦çã®å é ããåãåºãè¦ç´ ã®æ°ã§ãã
æ°ããã¤ãã¬ã¼ã¿ã¼ãã«ãã¼ãªãã¸ã§ã¯ãã§ããè¿ãããã¤ãã¬ã¼ã¿ã¼ãã«ãã¼ã¯ãå
ã®ã¤ãã¬ã¼ã¿ã¼ã®è¦ç´ ã 1 ã¤ãã¤çæãã limit
ã®æ°ã®è¦ç´ ãçæãããå ´åãã¾ãã¯å
ã®ã¤ãã¬ã¼ã¿ã¼ããã¹ã¦å¦çãããå ´åï¼next()
ã¡ã½ããã { value: undefined, done: true }
ãçæããå ´åï¼ã«ãå®äºãã¾ãã
RangeError
limit
ãæ´æ°ã«å¤æããå ´åã« NaN
ã¾ãã¯è² ã®æ°ã«ãªã£ãå ´åã
次ã®ä¾ã§ã¯ããã£ããããæ°åã®é ç®ãå復å¦çããã¤ãã¬ã¼ã¿ã¼ã使ããæåã® 3 ã¤ã®é ç®ããã°è¨é²ãã¾ãã
function* fibonacci() {
let current = 1;
let next = 1;
while (true) {
yield current;
[current, next] = [next, current + next];
}
}
const seq = fibonacci().take(3);
console.log(seq.next().value); // 1
console.log(seq.next().value); // 1
console.log(seq.next().value); // 2
console.log(seq.next().value); // undefined
take() ã for...of ã«ã¼ãã§ä½¿ç¨
take()
ã¯ãã¤ãã¬ã¼ã¿ã¼ãæä½æ¥ã§ä½æããªãå ´åã«æã便å©ã§ããã¤ãã¬ã¼ã¿ã¼ãå復å¯è½ãªãã¸ã§ã¯ãã§ãããããè¿ããããã«ãã¼ã for...of
ã«ã¼ãã§å復å¦çãããã¨ãã§ãã¾ãã
for (const n of fibonacci().take(5)) {
console.log(n);
}
// ãã°åºå:
// 1
// 1
// 2
// 3
// 5
fibonacci()
ã¯ç¡éã¤ãã¬ã¼ã¿ã¼ã§ãããããfor
ã«ã¼ãã使ç¨ãã¦ç´æ¥å復å¦çãããã¨ã¯ã§ãã¾ããã
take()
ã Iterator.prototype.drop()
ã¨çµåããã¨ãã¤ãã¬ã¼ã¿ã¼ã®ã¹ã©ã¤ã¹ãåå¾ãããã¨ãã§ãã¾ãã
for (const n of fibonacci().drop(2).take(5)) {
// æåã® 2 ã¤ã®è¦ç´ ãæ¨ã¦ã次㮠5 ã¤ãåã
console.log(n);
}
// ãã°åºå:
// 2
// 3
// 5
// 8
// 13
for (const n of fibonacci().take(5).drop(2)) {
// æåã®5ã¤ã®è¦ç´ ãåãããã®æ¬¡ã® 2 ã¤ãæ¨ã¦ã
console.log(n);
}
// ãã°åºå:
// 2
// 3
// 5
å徿°ã®ä¸éã¨ä¸é
limit
ãè² ã®æ°ã¾ã㯠NaN
ã§ãã£ãå ´åã RangeError
ãçºçãã¾ãã
fibonacci().take(-1); // RangeError: -1 must be positive
fibonacci().take(undefined); // RangeError: undefined must be positive
limit
ãå復å¯è½ãªãã¸ã§ã¯ãã®ç·æ°ããã大ããå ´åï¼Infinity
ãªã©ï¼ãè¿ãããã¤ãã¬ã¼ã¿ã¼ãã«ãã¼ã¯ãåºæ¬çã«å
ã®ã¤ãã¬ã¼ã¿ã¼ã¨åãåä½ããã¾ãã
for (const n of new Set([1, 2, 3]).values().take(Infinity)) {
console.log(n);
}
// ãã°åºå:
// 1
// 2
// 3
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4