Skip to content

Commit 801b5e3

Browse files
committed
Examples for for..of and spread
1 parent 4b116d9 commit 801b5e3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

JavaScript/d-for-of.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
function* ids(...args) {
4+
let i = 0;
5+
while (args.length > i) {
6+
const id = args[i++];
7+
if (id === undefined) return -1;
8+
yield id;
9+
}
10+
}
11+
12+
const id = ids(1011, 1078, 1292, 1731, undefined, 1501, 1550);
13+
for (const val of id) {
14+
console.log({ val });
15+
}

JavaScript/e-spread.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
function* ids(...args) {
4+
let i = 0;
5+
while (args.length > i) {
6+
const id = args[i++];
7+
if (id === undefined) return -1;
8+
yield id;
9+
}
10+
}
11+
12+
const id = ids(1011, 1078, 1292, 1731, undefined, 1501, 1550);
13+
console.log([...id]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy