-
-
Save egdelwonk/c2ce8ed5780224d7b845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array.from copies an array. | |
load(libdir + "asserts.js"); | |
var testArray = [1, 2, 3]; | |
//test that Array.from creates a new array | |
assertDeepEq(Array.from(testArray), testArray); | |
assertEq(Array.from(testArray) === testArray, false); | |
assertEq(Array.from(testArray) === Array.from(testArray), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If an object has both .length and [@@iterator] properties, [@@iterator] is used. | |
load(libdir + "iteration.js"); | |
load(libdir + "asserts.js"); | |
var a = ['a', 'e', 'i', 'o', 'u']; | |
a[std_iterator] = function* () { | |
for (var i = this.length; i--; ) | |
yield this[i]; | |
}; | |
var log = ''; | |
function f(x) { | |
log += x; | |
return x + x; | |
} | |
var b = Array.from(a, f); | |
assertDeepEq(b, ['uu', 'oo', 'ii', 'ee', 'aa']); | |
assertEq(log, 'uoiea'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array.from string | |
load(libdir + "asserts.js"); | |
var testString = "test string"; | |
assertDeepEq(Array.from(testString), ['t', 'e', 's', 't', ' ', 's', 't', 'r', 'i', 'n', 'g']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array.from string iterator maintains surrogate pairs. | |
load(libdir + "asserts.js"); | |
var pairString = "\uD834\uDF06"; | |
assertDeepEq(Array.from(pairString), [pairString]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array.from: Assert typeerror if arrayLike is undefined or null | |
load(libdir + "asserts.js"); | |
assertThrowsInstanceOf(() => Array.from(undefined), TypeError); | |
assertThrowsInstanceOf(() => Array.from(null), TypeError); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment