Skip to content

Commit 18e2e47

Browse files
authored
FixedArray
1 parent e2ce1ab commit 18e2e47

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎fixed size array‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ function createFixedSizeArray(...items) {
1111

1212
return array;
1313
}
14+
15+
// or
16+
class FixedArray {
17+
constructor(...items) {
18+
let array = [];
19+
20+
if (items.length === 1) {
21+
array = (new Array(items[0])).fill(undefined);
22+
} else {
23+
items.forEach((item, index) => array[index] = item)
24+
}
25+
26+
Object.seal(array);
27+
28+
return array;
29+
}
30+
}

0 commit comments

Comments
 (0)