1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright (c) 2021 Rick Waldron. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
esid: sec-array.from
description: >
Creates an array with length that is equal to the value of the
length property of the given array-like, regardless of
the presence of corresponding indices and values.
info: |
Array.from ( items [ , mapfn [ , thisArg ] ] )
7. Let arrayLike be ! ToObject(items).
8. Let len be ? LengthOfArrayLike(arrayLike).
9. If IsConstructor(C) is true, then
a. Let A be ? Construct(C, « 𝔽(len) »).
10. Else,
a. Let A be ? ArrayCreate(len).
includes: [compareArray.js]
---*/
const length = 5;
const newlyCreatedArray = Array.from({ length });
assert.sameValue(
newlyCreatedArray.length,
length,
"The newly created array's length is equal to the value of the length property for the provided array like object"
);
assert.compareArray(newlyCreatedArray, [undefined, undefined, undefined, undefined, undefined]);
const newlyCreatedAndMappedArray = Array.from({ length }).map(x => 1);
assert.sameValue(
newlyCreatedAndMappedArray.length,
length,
"The newly created and mapped array's length is equal to the value of the length property for the provided array like object"
);
assert.compareArray(newlyCreatedAndMappedArray, [1, 1, 1, 1, 1]);
reportCompare(0, 0);
|