diff --git a/database.json b/database.json new file mode 100644 index 0000000..062fd46 --- /dev/null +++ b/database.json @@ -0,0 +1,3 @@ +{ + "records": {} +} \ No newline at end of file diff --git a/desktop.ini b/desktop.ini new file mode 100644 index 0000000..bb9f3d6 --- /dev/null +++ b/desktop.ini @@ -0,0 +1,4 @@ +[ViewState] +Mode= +Vid= +FolderType=Generic diff --git a/meta.json b/meta.json new file mode 100644 index 0000000..24ef798 --- /dev/null +++ b/meta.json @@ -0,0 +1,17 @@ +[ + { + "fileName": "sharedarraybuffer-bytelength.js", + "title": "JavaScript: SharedArrayBuffer.byteLength", + "type": "js" + }, + { + "fileName": "sharedarraybuffer-constructor.js", + "title": "JavaScript: SharedArrayBuffer Constructor", + "type": "js" + }, + { + "fileName": "sharedarraybuffer-slice.js", + "title": "JavaScript: SharedArrayBuffer.slice()", + "type": "js" + } +] \ No newline at end of file diff --git a/string-charat.js b/string-charat.js new file mode 100644 index 0000000..d855e47 --- /dev/null +++ b/string-charat.js @@ -0,0 +1,6 @@ +var sentence = 'The quick brown fox jumps over the lazy dog.'; + +var index = 4; + +console.log('The character at index ' + index + ' is ' + sentence.charAt(index)); +// expected output: "The character at index 4 is q" \ No newline at end of file diff --git a/string-charcodeat.js b/string-charcodeat.js new file mode 100644 index 0000000..0de18f7 --- /dev/null +++ b/string-charcodeat.js @@ -0,0 +1,6 @@ +var sentence = 'The quick brown fox jumps over the lazy dog.'; + +var index = 4; + +console.log('The character code ' + sentence.charCodeAt(index) + ' is equal to ' + sentence.charAt(index)); +// expected output: "The character code 113 is equal to q" \ No newline at end of file diff --git a/string-codepointat.js b/string-codepointat.js new file mode 100644 index 0000000..d8d6b81 --- /dev/null +++ b/string-codepointat.js @@ -0,0 +1,4 @@ +var icons = '☃★♲'; + +console.log(icons.codePointAt(1)); +// expected output: "9733" \ No newline at end of file diff --git a/string-concat.js b/string-concat.js new file mode 100644 index 0000000..7f5d7b5 --- /dev/null +++ b/string-concat.js @@ -0,0 +1,8 @@ +var str1 = 'Hello'; +var str2 = 'World'; + +console.log(str1.concat(' ', str2)); +// expected output: "Hello World" + +console.log(str2.concat(', ', str1)); +// expected output: "World, Hello" \ No newline at end of file diff --git a/string-endswith.js b/string-endswith.js new file mode 100644 index 0000000..8db539e --- /dev/null +++ b/string-endswith.js @@ -0,0 +1,9 @@ +const str1 = 'Cats are the best!'; + +console.log(str1.endsWith('best', 17)); +// expected output: true + +const str2 = 'Is this a question'; + +console.log(str2.endsWith('?')); +// expected output: false \ No newline at end of file diff --git a/string-fromcharcode.js b/string-fromcharcode.js new file mode 100644 index 0000000..4dd66ea --- /dev/null +++ b/string-fromcharcode.js @@ -0,0 +1,2 @@ +console.log(String.fromCharCode(189, 43, 190, 61)); +// expected output: "½+¾=" \ No newline at end of file diff --git a/string-fromcodepoint.js b/string-fromcodepoint.js new file mode 100644 index 0000000..f46b0ca --- /dev/null +++ b/string-fromcodepoint.js @@ -0,0 +1,2 @@ +console.log(String.fromCodePoint(65, 90, 48)); +// expected output: "AZ0" \ No newline at end of file diff --git a/string-includes.js b/string-includes.js new file mode 100644 index 0000000..98619ee --- /dev/null +++ b/string-includes.js @@ -0,0 +1,6 @@ +var sentence = 'The quick brown fox jumps over the lazy dog.'; + +var word = 'fox'; + +console.log(`The word "${word}" ${sentence.includes(word)? 'is' : 'is not'} in the sentence`); +// expected output: "The word "fox" is in the sentence" \ No newline at end of file diff --git a/string-indexof.js b/string-indexof.js new file mode 100644 index 0000000..d7400e1 --- /dev/null +++ b/string-indexof.js @@ -0,0 +1,10 @@ +var paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; + +var searchTerm = 'dog'; +var indexOfFirst = paragraph.indexOf(searchTerm); + +console.log('The index of the first "' + searchTerm + '" from the beginning is ' + indexOfFirst); +// expected output: "The index of the first "dog" from the beginning is 40" + +console.log('The index of the 2nd "' + searchTerm + '" is ' + paragraph.indexOf(searchTerm, (indexOfFirst + 1))); +// expected output: "The index of the 2nd "dog" is 52" \ No newline at end of file diff --git a/string-iterator.js b/string-iterator.js new file mode 100644 index 0000000..fb9b70b --- /dev/null +++ b/string-iterator.js @@ -0,0 +1,12 @@ +const str = 'The quick red fox jumped over the lazy dog\'s back.'; + +let iterator = str[Symbol.iterator](); +let theChar = iterator.next(); + +while(!theChar.done && theChar.value !== ' ') { + console.log(theChar.value); + theChar = iterator.next(); + // expected output: "T" + // "h" + // "e" +} \ No newline at end of file diff --git a/string-lastindexof.js b/string-lastindexof.js new file mode 100644 index 0000000..fb48920 --- /dev/null +++ b/string-lastindexof.js @@ -0,0 +1,6 @@ +var paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; + +var searchTerm = 'dog'; + +console.log('The index of the first "' + searchTerm + '" from the end is ' + paragraph.lastIndexOf(searchTerm)); +// expected output: "The index of the first "dog" from the end is 52" \ No newline at end of file diff --git a/string-length.js b/string-length.js new file mode 100644 index 0000000..253bc11 --- /dev/null +++ b/string-length.js @@ -0,0 +1,4 @@ +var str = 'Life, the universe and everything. Answer:'; + +console.log(str + ' ' + str.length); +// expected output: "Life, the universe and everything. Answer: 42" \ No newline at end of file diff --git a/string-localecompare.js b/string-localecompare.js new file mode 100644 index 0000000..3031084 --- /dev/null +++ b/string-localecompare.js @@ -0,0 +1,7 @@ +var a = 'réservé'; // with accents, lowercase +var b = 'RESERVE'; // no accents, uppercase + +console.log(a.localeCompare(b)); +// expected output: 1 +console.log(a.localeCompare(b, 'en', {sensitivity: 'base'})); +// expected output: 0 \ No newline at end of file diff --git a/string-match.js b/string-match.js new file mode 100644 index 0000000..0776efb --- /dev/null +++ b/string-match.js @@ -0,0 +1,6 @@ +var paragraph = 'The quick brown fox jumps over the lazy dog. It barked.'; +var regex = /[A-Z]/g; +var found = paragraph.match(regex); + +console.log(found); +// expected output: Array ["T", "I"] \ No newline at end of file diff --git a/string-matchall.js b/string-matchall.js new file mode 100644 index 0000000..97d9f70 --- /dev/null +++ b/string-matchall.js @@ -0,0 +1,10 @@ +let regexp = /t(e)(st(\d?))/g; +let str = 'test1test2'; + +let array = [...str.matchAll(regexp)]; + +console.log(array[0]); +// expected output: Array ["test1", "e", "st1", "1"] + +console.log(array[1]); +// expected output: Array ["test2", "e", "st2", "2"] \ No newline at end of file diff --git a/string-normalize.js b/string-normalize.js new file mode 100644 index 0000000..3d9c60c --- /dev/null +++ b/string-normalize.js @@ -0,0 +1,15 @@ +var first = '\u212B'; // "Å" +var second = '\u0041\u030A'; // "Å" + +console.log(first + ' and ' + second + ' are' + + ((first === second)? '': ' not') + ' the same.'); + // expected output: "Å and Å are not the same." + +console.log(first + ' and ' + second + ' can' + + ((first.normalize('NFC') === second.normalize('NFC'))? '': ' not') + ' be normalized'); + // expected output: "Å and Å can be normalized" + +var oldWord = 'mañana'; +var newWord = oldWord.normalize('NFD'); +console.log('The word did ' + ((oldWord != newWord)? '' : 'not ') + 'change.'); +// expected output: "The word did change." \ No newline at end of file diff --git a/string-padend.js b/string-padend.js new file mode 100644 index 0000000..2059b61 --- /dev/null +++ b/string-padend.js @@ -0,0 +1,9 @@ +const str1 = 'Breaded Mushrooms'; + +console.log(str1.padEnd(25, '.')); +// expected output: "Breaded Mushrooms........" + +const str2 = '200'; + +console.log(str2.padEnd(5)); +// expected output: "200 " \ No newline at end of file diff --git a/string-padstart.js b/string-padstart.js new file mode 100644 index 0000000..66e5f55 --- /dev/null +++ b/string-padstart.js @@ -0,0 +1,11 @@ +const str1 = '5'; + +console.log(str1.padStart(2, '0')); +// expected output: "05" + +const fullNumber = '2034399002125581'; +const last4Digits = fullNumber.slice(-4); +const maskedNumber = last4Digits.padStart(fullNumber.length, '*'); + +console.log(maskedNumber); +// expected output: "************5581" \ No newline at end of file diff --git a/string-raw.js b/string-raw.js new file mode 100644 index 0000000..7b76b7f --- /dev/null +++ b/string-raw.js @@ -0,0 +1,6 @@ +// Create a variable that uses a Windows +// path without escaping the backslashes: +const filePath = String.raw`C:\Development\profile\aboutme.html`; + +console.log('The file was uploaded from: ' + filePath); +// expected output: "The file was uploaded from: C:\Development\profile\aboutme.html" \ No newline at end of file diff --git a/string-repeat.js b/string-repeat.js new file mode 100644 index 0000000..babf015 --- /dev/null +++ b/string-repeat.js @@ -0,0 +1,5 @@ +var chorus = 'Because I\'m happy. '; + +console.log('Chorus lyrics for "Happy": ' + chorus.repeat(27)); + +// expected output: "Chorus lyrics for "Happy": Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. Because I'm happy. " \ No newline at end of file diff --git a/string-replace.js b/string-replace.js new file mode 100644 index 0000000..ccf8a46 --- /dev/null +++ b/string-replace.js @@ -0,0 +1,9 @@ +var p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?'; + +var regex = /dog/gi; + +console.log(p.replace(regex, 'ferret')); +// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?" + +console.log(p.replace('dog', 'monkey')); +// expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?" \ No newline at end of file diff --git a/string-search.js b/string-search.js new file mode 100644 index 0000000..77c67b6 --- /dev/null +++ b/string-search.js @@ -0,0 +1,10 @@ +var paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; + +// any character that is not a word character or whitespace +var regex = /[^\w\s]/g; + +console.log(paragraph.search(regex)); +// expected output: 43 + +console.log(paragraph[paragraph.search(regex)]); +// expected output: "." \ No newline at end of file diff --git a/string-slice.js b/string-slice.js new file mode 100644 index 0000000..1ea8bb1 --- /dev/null +++ b/string-slice.js @@ -0,0 +1,13 @@ +var str = 'The quick brown fox jumps over the lazy dog.'; + +console.log(str.slice(31)); +// expected output: "the lazy dog." + +console.log(str.slice(4, 19)); +// expected output: "quick brown fox" + +console.log(str.slice(-4)); +// expected output: "dog." + +console.log(str.slice(-9, -5)); +// expected output: "lazy" \ No newline at end of file diff --git a/string-split.js b/string-split.js new file mode 100644 index 0000000..4b58b12 --- /dev/null +++ b/string-split.js @@ -0,0 +1,13 @@ +var str = 'The quick brown fox jumps over the lazy dog.'; + +var words = str.split(' '); +console.log(words[3]); +// expected output: "fox" + +var chars = str.split(''); +console.log(chars[8]); +// expected output: "k" + +var strCopy = str.split(); +console.log(strCopy); +// expected output: Array ["The quick brown fox jumps over the lazy dog."] \ No newline at end of file diff --git a/string-startswith.js b/string-startswith.js new file mode 100644 index 0000000..02a2d25 --- /dev/null +++ b/string-startswith.js @@ -0,0 +1,7 @@ +const str1 = 'Saturday night plans'; + +console.log(str1.startsWith('Sat')); +// expected output: true + +console.log(str1.startsWith('Sat', 3)); +// expected output: false \ No newline at end of file diff --git a/string-substr.js b/string-substr.js new file mode 100644 index 0000000..fd12915 --- /dev/null +++ b/string-substr.js @@ -0,0 +1,7 @@ +var str = 'Mozilla'; + +console.log(str.substr(1, 2)); +// expected output: "oz" + +console.log(str.substr(2)); +// expected output: "zilla" \ No newline at end of file diff --git a/string-substring.js b/string-substring.js new file mode 100644 index 0000000..66aceb9 --- /dev/null +++ b/string-substring.js @@ -0,0 +1,7 @@ +var str = 'Mozilla'; + +console.log(str.substring(1, 3)); +// expected output: "oz" + +console.log(str.substring(2)); +// expected output: "zilla" \ No newline at end of file diff --git a/string-tolocalelowercase.js b/string-tolocalelowercase.js new file mode 100644 index 0000000..e856c2a --- /dev/null +++ b/string-tolocalelowercase.js @@ -0,0 +1,7 @@ +var dotted = 'İstanbul'; + +console.log('EN-US: ' + dotted.toLocaleLowerCase('en-US')); +// expected output: "i̇stanbul" + +console.log('TR: ' + dotted.toLocaleLowerCase('tr')); +// expected output: "istanbul" \ No newline at end of file diff --git a/string-tolocaleuppercase.js b/string-tolocaleuppercase.js new file mode 100644 index 0000000..df7d008 --- /dev/null +++ b/string-tolocaleuppercase.js @@ -0,0 +1,7 @@ +var city = 'istanbul'; + +console.log(city.toLocaleUpperCase('en-US')); +// expected output: "ISTANBUL" + +console.log(city.toLocaleUpperCase('TR')); +// expected output: "İSTANBUL" \ No newline at end of file diff --git a/string-tolowercase.js b/string-tolowercase.js new file mode 100644 index 0000000..4a5f3ba --- /dev/null +++ b/string-tolowercase.js @@ -0,0 +1,4 @@ +var sentence = 'The quick brown fox jumps over the lazy dog.'; + +console.log(sentence.toLowerCase()); +// expected output: "the quick brown fox jumps over the lazy dog." \ No newline at end of file diff --git a/string-tostring.js b/string-tostring.js new file mode 100644 index 0000000..504e431 --- /dev/null +++ b/string-tostring.js @@ -0,0 +1,7 @@ +var stringObj = new String("foo"); + +console.log(stringObj); +// expected output: String { "foo" } + +console.log(stringObj.toString()); +// expected output: "foo" \ No newline at end of file diff --git a/string-touppercase.js b/string-touppercase.js new file mode 100644 index 0000000..4fa5b5a --- /dev/null +++ b/string-touppercase.js @@ -0,0 +1,4 @@ +var sentence = 'The quick brown fox jumps over the lazy dog.'; + +console.log(sentence.toUpperCase()); +// expected output: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG." \ No newline at end of file diff --git a/string-trim.js b/string-trim.js new file mode 100644 index 0000000..ead8173 --- /dev/null +++ b/string-trim.js @@ -0,0 +1,7 @@ +var greeting = ' Hello world! '; + +console.log(greeting); +// expected output: " Hello world! "; + +console.log(greeting.trim()); +// expected output: "Hello world!"; \ No newline at end of file diff --git a/string-trimend.js b/string-trimend.js new file mode 100644 index 0000000..0a1768f --- /dev/null +++ b/string-trimend.js @@ -0,0 +1,7 @@ +var greeting = ' Hello world! '; + +console.log(greeting); +// expected output: " Hello world! "; + +console.log(greeting.trimEnd()); +// expected output: " Hello world!"; \ No newline at end of file diff --git a/string-trimstart.js b/string-trimstart.js new file mode 100644 index 0000000..c55da8a --- /dev/null +++ b/string-trimstart.js @@ -0,0 +1,7 @@ +var greeting = ' Hello world! '; + +console.log(greeting); +// expected output: " Hello world! "; + +console.log(greeting.trimStart()); +// expected output: "Hello world! "; \ No newline at end of file diff --git a/string-valueof.js b/string-valueof.js new file mode 100644 index 0000000..8131b89 --- /dev/null +++ b/string-valueof.js @@ -0,0 +1,7 @@ +var stringObj = new String("foo"); + +console.log(stringObj); +// expected output: String { "foo" } + +console.log(stringObj.valueOf()); +// expected output: "foo" \ No newline at end of file diff --git a/symbol-constructor.js b/symbol-constructor.js new file mode 100644 index 0000000..be2a766 --- /dev/null +++ b/symbol-constructor.js @@ -0,0 +1,12 @@ +const symbol1 = Symbol(); +const symbol2 = Symbol(42); +const symbol3 = Symbol('foo'); + +console.log(typeof symbol1); +// expected output: "symbol" + +console.log(symbol3.toString()); +// expected output: "Symbol(foo)" + +console.log(Symbol('foo') === Symbol('foo')); +// expected output: false \ No newline at end of file diff --git a/symbol-for.js b/symbol-for.js new file mode 100644 index 0000000..a8f92a5 --- /dev/null +++ b/symbol-for.js @@ -0,0 +1,10 @@ +console.log(Symbol.for('bar') === Symbol.for('bar')); +// expected output: true + +console.log(Symbol('bar') === Symbol('bar')); +// expected output: false + +const symbol1 = Symbol.for('foo'); + +console.log(symbol1.toString()); +// expected output: "Symbol(foo)" \ No newline at end of file diff --git a/symbol-hasinstance.js b/symbol-hasinstance.js new file mode 100644 index 0000000..207c9d0 --- /dev/null +++ b/symbol-hasinstance.js @@ -0,0 +1,8 @@ +class Array1 { + static [Symbol.hasInstance](instance) { + return Array.isArray(instance); + } +} + +console.log([] instanceof Array1); +// expected output: true \ No newline at end of file diff --git a/symbol-isconcatspreadable.js b/symbol-isconcatspreadable.js new file mode 100644 index 0000000..c9c604f --- /dev/null +++ b/symbol-isconcatspreadable.js @@ -0,0 +1,12 @@ +const alpha = ['a', 'b', 'c']; +const numeric = [1, 2, 3]; +let alphaNumeric = alpha.concat(numeric); + +console.log(alphaNumeric); +// expected output: Array ["a", "b", "c", 1, 2, 3] + +numeric[Symbol.isConcatSpreadable] = false; +alphaNumeric = alpha.concat(numeric); + +console.log(alphaNumeric); +// expected output: Array ["a", "b", "c", Array [1, 2, 3]] \ No newline at end of file diff --git a/symbol-iterator.js b/symbol-iterator.js new file mode 100644 index 0000000..a2c1d10 --- /dev/null +++ b/symbol-iterator.js @@ -0,0 +1,10 @@ +const iterable1 = new Object(); + +iterable1[Symbol.iterator] = function* () { + yield 1; + yield 2; + yield 3; +}; + +console.log([...iterable1]); +// expected output: Array [1, 2, 3] \ No newline at end of file diff --git a/symbol-keyfor.js b/symbol-keyfor.js new file mode 100644 index 0000000..03a9157 --- /dev/null +++ b/symbol-keyfor.js @@ -0,0 +1,12 @@ +const globalSym = Symbol.for('foo'); // global symbol + +console.log(Symbol.keyFor(globalSym)); +// expected output: "foo" + +const localSym = Symbol(); // local symbol + +console.log(Symbol.keyFor(localSym)); +// expected output: undefined + +console.log(Symbol.keyFor(Symbol.iterator)); +// expected output: undefined \ No newline at end of file diff --git a/symbol-match.js b/symbol-match.js new file mode 100644 index 0000000..a5329f9 --- /dev/null +++ b/symbol-match.js @@ -0,0 +1,12 @@ +const regexp1 = /foo/; +// console.log('/foo/'.startsWith(regexp1)); +// expected output: (Chrome) Error: First argument to String.prototype.startsWith must not be a regular expression +// expected output: (Firefox) Error: Invalid type: first can't be a Regular Expression + +regexp1[Symbol.match] = false; + +console.log('/foo/'.startsWith(regexp1)); +// expected output: true + +console.log('/baz/'.endsWith(regexp1)); +// expected output: false \ No newline at end of file diff --git a/symbol-matchall.js b/symbol-matchall.js new file mode 100644 index 0000000..3d3b308 --- /dev/null +++ b/symbol-matchall.js @@ -0,0 +1,6 @@ +let re = /[0-9]+/g; +let str = '2016-01-02|2019-03-07'; +let result = re[Symbol.matchAll](str); + +console.log(Array.from(result, x => x[0])); +// expected output: Array ["2016", "01", "02", "2019", "03", "07"] \ No newline at end of file diff --git a/symbol-prototype-description.js b/symbol-prototype-description.js new file mode 100644 index 0000000..711348d --- /dev/null +++ b/symbol-prototype-description.js @@ -0,0 +1,11 @@ +console.log(Symbol('desc').description); +// expected output: "desc" + +console.log(Symbol.iterator.description); +// expected output: "Symbol.iterator" + +console.log(Symbol.for('foo').description); +// expected output: "foo" + +console.log(Symbol('foo').description + 'bar'); +// expected output: "foobar" \ No newline at end of file diff --git a/symbol-prototype-tostring.js b/symbol-prototype-tostring.js new file mode 100644 index 0000000..f900c44 --- /dev/null +++ b/symbol-prototype-tostring.js @@ -0,0 +1,11 @@ +console.log(Symbol('desc').toString()); +// expected output: "Symbol(desc)" + +console.log(Symbol.iterator.toString()); +// expected output: "Symbol(Symbol.iterator) + +console.log(Symbol.for('foo').toString()); +// expected output: "Symbol(foo)" + +// console.log(Symbol('foo') + 'bar'); +// expected output: Error: Can't convert symbol to string \ No newline at end of file diff --git a/symbol-prototype.js b/symbol-prototype.js new file mode 100644 index 0000000..1862026 --- /dev/null +++ b/symbol-prototype.js @@ -0,0 +1,8 @@ +Symbol.prototype.toString = function() { + return ('SYMBOL'); +} + +var symbol1 = Symbol('foo'); + +console.log(symbol1.toString()); +// expected output: "SYMBOL" \ No newline at end of file diff --git a/symbol-replace.js b/symbol-replace.js new file mode 100644 index 0000000..d968a06 --- /dev/null +++ b/symbol-replace.js @@ -0,0 +1,11 @@ +class Replace1 { + constructor(value) { + this.value = value; + } + [Symbol.replace](string) { + return `s/${string}/${this.value}/g`; + } +} + +console.log('foo'.replace(new Replace1('bar'))); +// expected output: "s/foo/bar/g" \ No newline at end of file diff --git a/symbol-search.js b/symbol-search.js new file mode 100644 index 0000000..b2652d5 --- /dev/null +++ b/symbol-search.js @@ -0,0 +1,11 @@ +class Search1 { + constructor(value) { + this.value = value; + } + [Symbol.search](string) { + return string.indexOf(this.value); + } +} + +console.log('foobar'.search(new Search1('bar'))); +// expected output: 3 \ No newline at end of file diff --git a/symbol-species.js b/symbol-species.js new file mode 100644 index 0000000..cefe86f --- /dev/null +++ b/symbol-species.js @@ -0,0 +1,12 @@ +class Array1 extends Array { + static get [Symbol.species]() { return Array; } +} + +const a = new Array1(1, 2, 3); +const mapped = a.map(x => x * x); + +console.log(mapped instanceof Array1); +// expected output: false + +console.log(mapped instanceof Array); +// expected output: true \ No newline at end of file diff --git a/symbol-split.js b/symbol-split.js new file mode 100644 index 0000000..fc79c76 --- /dev/null +++ b/symbol-split.js @@ -0,0 +1,13 @@ +class Split1 { + constructor(value) { + this.value = value; + } + [Symbol.split](string) { + var index = string.indexOf(this.value); + return this.value + string.substr(0, index) + "/" + + string.substr(index + this.value.length); + } +} + +console.log('foobar'.split(new Split1('foo'))); +// expected output: "foo/bar" \ No newline at end of file diff --git a/symbol-toprimitive.js b/symbol-toprimitive.js new file mode 100644 index 0000000..97cb3d4 --- /dev/null +++ b/symbol-toprimitive.js @@ -0,0 +1,11 @@ +const object1 = { + [Symbol.toPrimitive](hint) { + if (hint == 'number') { + return 42; + } + return null; + } +}; + +console.log(+object1); +// expected output: 42 \ No newline at end of file diff --git a/symbol-tostringtag.js b/symbol-tostringtag.js new file mode 100644 index 0000000..908505c --- /dev/null +++ b/symbol-tostringtag.js @@ -0,0 +1,8 @@ +class ValidatorClass { + get [Symbol.toStringTag]() { + return 'Validator'; + } +} + +console.log(Object.prototype.toString.call(new ValidatorClass())); +// expected output: "[object Validator]" \ No newline at end of file diff --git a/symbol-unscopables.js b/symbol-unscopables.js new file mode 100644 index 0000000..7cbc87b --- /dev/null +++ b/symbol-unscopables.js @@ -0,0 +1,12 @@ +const object1 = { + property1: 42 +}; + +object1[Symbol.unscopables] = { + property1: true +}; + +with (object1) { + console.log(property1); + // expected output: Error: property1 is not defined +} \ No newline at end of file diff --git a/typedarray-buffer.js b/typedarray-buffer.js new file mode 100644 index 0000000..cb3e4a2 --- /dev/null +++ b/typedarray-buffer.js @@ -0,0 +1,6 @@ +// create an ArrayBuffer with a size in bytes +const buffer = new ArrayBuffer(8); +const uint16 = new Uint16Array(buffer); + +console.log(uint16.buffer.byteLength); +// expected output: 8 \ No newline at end of file diff --git a/typedarray-bytelength.js b/typedarray-bytelength.js new file mode 100644 index 0000000..929a290 --- /dev/null +++ b/typedarray-bytelength.js @@ -0,0 +1,6 @@ +// create an ArrayBuffer with a size in bytes +const buffer = new ArrayBuffer(8); +const uint8 = new Uint8Array(buffer, 2); + +console.log (uint8.byteLength); +// expected output: 6 \ No newline at end of file diff --git a/typedarray-bytes-per-element.js b/typedarray-bytes-per-element.js new file mode 100644 index 0000000..27f973a --- /dev/null +++ b/typedarray-bytes-per-element.js @@ -0,0 +1,5 @@ +console.log(Float64Array.BYTES_PER_ELEMENT); +// expected output: 8 + +console.log(Int8Array.BYTES_PER_ELEMENT); +// expected output: 1 \ No newline at end of file diff --git a/typedarray-constructor.js b/typedarray-constructor.js new file mode 100644 index 0000000..98b6689 --- /dev/null +++ b/typedarray-constructor.js @@ -0,0 +1,12 @@ +// create a TypedArray with a size in bytes +const typedArray1 = new Int8Array(8); +typedArray1[0] = 32; + +const typedArray2 = new Int8Array(typedArray1); +typedArray2[1] = 42; + +console.log(typedArray1); +// expected output: Int8Array [32, 0, 0, 0, 0, 0, 0, 0] + +console.log(typedArray2); +// expected output: Int8Array [32, 42, 0, 0, 0, 0, 0, 0] \ No newline at end of file diff --git a/typedarray-copywithin.js b/typedarray-copywithin.js new file mode 100644 index 0000000..6ee50cc --- /dev/null +++ b/typedarray-copywithin.js @@ -0,0 +1,7 @@ +const uint8 = new Uint8Array([ 1, 2, 3, 4, 5, 6, 7, 8 ]); + +// (insert position, start position, end position) +uint8.copyWithin(3, 1, 3); + +console.log(uint8); +// expected output: Uint8Array [1, 2, 3, 2, 3, 6, 7, 8] \ No newline at end of file diff --git a/typedarray-entries.js b/typedarray-entries.js new file mode 100644 index 0000000..20ec7e8 --- /dev/null +++ b/typedarray-entries.js @@ -0,0 +1,8 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); +eArr = uint8.entries(); + +eArr.next(); +eArr.next(); + +console.log(eArr.next().value); +// expected output: Array [2, 30] \ No newline at end of file diff --git a/typedarray-every.js b/typedarray-every.js new file mode 100644 index 0000000..4b2433d --- /dev/null +++ b/typedarray-every.js @@ -0,0 +1,8 @@ +function isNegative(element, index, array) { + return element < 0; +} + +const int8 = new Int8Array([-10, -20, -30, -40, -50]); + +console.log(int8.every(isNegative)); +// expected output: true \ No newline at end of file diff --git a/typedarray-fill.js b/typedarray-fill.js new file mode 100644 index 0000000..449d7ff --- /dev/null +++ b/typedarray-fill.js @@ -0,0 +1,6 @@ +const uint8 = new Uint8Array([0, 0, 0, 0]); +// (value, start position, end position); +uint8.fill(4, 1, 3); + +console.log(uint8); +// expected output: Uint8Array [0, 4, 4, 0] \ No newline at end of file diff --git a/typedarray-filter.js b/typedarray-filter.js new file mode 100644 index 0000000..65a941e --- /dev/null +++ b/typedarray-filter.js @@ -0,0 +1,9 @@ +function isNegative(element, index, array) { + return element < 0; +} + +const int8 = new Int8Array([-10, 20, -30, 40, -50]); +const negInt8 = int8.filter(isNegative); + +console.log(negInt8); +// expected output: Int8Array [-10, -30, -50] \ No newline at end of file diff --git a/typedarray-find.js b/typedarray-find.js new file mode 100644 index 0000000..2c3b7e5 --- /dev/null +++ b/typedarray-find.js @@ -0,0 +1,8 @@ +function isNegative(element, index, array) { + return element < 0; +} + +const int8 = new Int8Array([10, 0, -10, 20, -30, 40, -50]); + +console.log(int8.find(isNegative)); +// expected output: -10 \ No newline at end of file diff --git a/typedarray-findindex.js b/typedarray-findindex.js new file mode 100644 index 0000000..d81b662 --- /dev/null +++ b/typedarray-findindex.js @@ -0,0 +1,8 @@ +function isNegative(element, index, array) { + return element < 0; +} + +const int8 = new Int8Array([10, -20, 30, -40, 50]); + +console.log(int8.findIndex(isNegative)); +// expected output: 1 \ No newline at end of file diff --git a/typedarray-from.js b/typedarray-from.js new file mode 100644 index 0000000..04e12b6 --- /dev/null +++ b/typedarray-from.js @@ -0,0 +1,5 @@ +let uint16 = new Int16Array; +uint16 = Int16Array.from('12345'); + +console.log(uint16); +// expected output: Int16Array [1, 2, 3, 4, 5] \ No newline at end of file diff --git a/typedarray-includes.js b/typedarray-includes.js new file mode 100644 index 0000000..02ca367 --- /dev/null +++ b/typedarray-includes.js @@ -0,0 +1,8 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); + +console.log(uint8.includes(20)); +// expected output: true + +// check from position 3 +console.log(uint8.includes(20, 3)); +// expected output: false \ No newline at end of file diff --git a/typedarray-indexof.js b/typedarray-indexof.js new file mode 100644 index 0000000..1a61fc0 --- /dev/null +++ b/typedarray-indexof.js @@ -0,0 +1,11 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); + +console.log(uint8.indexOf(50)); +// expected output: 4 + +// from position 3 +console.log(uint8.indexOf(20, 3)); +// expected output: -1 + +console.log(uint8.indexOf(51)); +// expected output: -1 \ No newline at end of file diff --git a/typedarray-join.js b/typedarray-join.js new file mode 100644 index 0000000..64af770 --- /dev/null +++ b/typedarray-join.js @@ -0,0 +1,10 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); + +console.log(uint8.join()); +// expected output: "10,20,30,40,50" + +console.log(uint8.join('')); +// expected output: "1020304050" + +console.log(uint8.join('-')); +// expected output: "10-20-30-40-50" \ No newline at end of file diff --git a/typedarray-keys.js b/typedarray-keys.js new file mode 100644 index 0000000..e07ee7f --- /dev/null +++ b/typedarray-keys.js @@ -0,0 +1,8 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); +const keys = uint8.keys(); + +keys.next(); +keys.next(); + +console.log(keys.next().value); +// expected output: 2 \ No newline at end of file diff --git a/typedarray-lastindexof.js b/typedarray-lastindexof.js new file mode 100644 index 0000000..95ecba9 --- /dev/null +++ b/typedarray-lastindexof.js @@ -0,0 +1,7 @@ +const uint8 = new Uint8Array([10, 20, 50, 50, 50, 60]); + +console.log(uint8.lastIndexOf(50, 5)); +// expected output: 4 + +console.log(uint8.lastIndexOf(50, 3)); +// expected output: 3 \ No newline at end of file diff --git a/typedarray-length.js b/typedarray-length.js new file mode 100644 index 0000000..462ec6d --- /dev/null +++ b/typedarray-length.js @@ -0,0 +1,6 @@ +// create an ArrayBuffer with a size in bytes +const buffer = new ArrayBuffer(8); +const uint8 = new Uint8Array(buffer, 2); + +console.log (uint8.length); +// expected output: 6 \ No newline at end of file diff --git a/typedarray-map.js b/typedarray-map.js new file mode 100644 index 0000000..191c25e --- /dev/null +++ b/typedarray-map.js @@ -0,0 +1,5 @@ +const uint8 = new Uint8Array([25, 36, 49]); +const roots = uint8.map(Math.sqrt); + +console.log(roots); +// expected output: Uint8Array [5, 6, 7] \ No newline at end of file diff --git a/typedarray-name.js b/typedarray-name.js new file mode 100644 index 0000000..9dfe743 --- /dev/null +++ b/typedarray-name.js @@ -0,0 +1,5 @@ +console.log(Uint8Array.name); +// expected output: "Uint8Array" + +console.log(Float32Array.name); +// expected output: "Float32Array" \ No newline at end of file diff --git a/typedarray-of.js b/typedarray-of.js new file mode 100644 index 0000000..f4f15a4 --- /dev/null +++ b/typedarray-of.js @@ -0,0 +1,5 @@ +let uint16 = new Int16Array; +uint16 = Int16Array.of('10', '20', '30', '40' ,'50'); + +console.log(uint16); +// expected output: Int16Array [10, 20, 30, 40, 50] \ No newline at end of file diff --git a/typedarray-reduce.js b/typedarray-reduce.js new file mode 100644 index 0000000..a40c7ac --- /dev/null +++ b/typedarray-reduce.js @@ -0,0 +1,8 @@ +const uint8 = new Uint8Array([0, 1, 2, 3]); + +function sum(previousValue, currentValue) { + return previousValue + currentValue; +} + +console.log(uint8.reduce(sum)); +// expected output: 6 \ No newline at end of file diff --git a/typedarray-reverse.js b/typedarray-reverse.js new file mode 100644 index 0000000..39ea394 --- /dev/null +++ b/typedarray-reverse.js @@ -0,0 +1,5 @@ +const uint8 = new Uint8Array([1, 2, 3]); +uint8.reverse(); + +console.log(uint8); +// expected output: Uint8Array [3, 2, 1] \ No newline at end of file diff --git a/typedarray-set.js b/typedarray-set.js new file mode 100644 index 0000000..cb6de3a --- /dev/null +++ b/typedarray-set.js @@ -0,0 +1,9 @@ +// create an ArrayBuffer with a size in bytes +const buffer = new ArrayBuffer(8); +const uint8 = new Uint8Array(buffer); + +// Copy the values into the array starting at index 3 +uint8.set([1, 2, 3], 3); + +console.log(uint8); +// expected output: Uint8Array [0, 0, 0, 1, 2, 3, 0, 0] \ No newline at end of file diff --git a/typedarray-slice.js b/typedarray-slice.js new file mode 100644 index 0000000..893d16f --- /dev/null +++ b/typedarray-slice.js @@ -0,0 +1,5 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); +const array1 = uint8.slice(1, 3); + +console.log(array1); +// expected output: Uint8Array [20, 30] \ No newline at end of file diff --git a/typedarray-some.js b/typedarray-some.js new file mode 100644 index 0000000..b3be9ee --- /dev/null +++ b/typedarray-some.js @@ -0,0 +1,12 @@ +function isNegative(element, index, array) { + return element < 0; +} + +const int8 = new Int8Array([-10, 20, -30, 40, -50]); +const positives = new Int8Array([10, 20, 30, 40, 50]); + +console.log(int8.some(isNegative)); +// expected output: true + +console.log(positives.some(isNegative)); +// expected output: false \ No newline at end of file diff --git a/typedarray-sort.js b/typedarray-sort.js new file mode 100644 index 0000000..35fbc95 --- /dev/null +++ b/typedarray-sort.js @@ -0,0 +1,5 @@ +const uint8 = new Uint8Array([40, 10, 50, 20, 30]); +uint8.sort(); + +console.log(uint8); +// expected output: Uint8Array [10, 20, 30, 40, 50] \ No newline at end of file diff --git a/typedarray-subarray.js b/typedarray-subarray.js new file mode 100644 index 0000000..9136e44 --- /dev/null +++ b/typedarray-subarray.js @@ -0,0 +1,7 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); + +console.log(uint8.subarray(1, 3)); +// expected output: Uint8Array [20, 30] + +console.log(uint8.subarray(1)); +// expected output: Uint8Array [20, 30, 40, 50] \ No newline at end of file diff --git a/typedarray-tostring.js b/typedarray-tostring.js new file mode 100644 index 0000000..97c2797 --- /dev/null +++ b/typedarray-tostring.js @@ -0,0 +1,6 @@ +const uint8 = new Uint8Array([10, 20, 30, 40, 50]); + +const uint8String = uint8.toString(); + +console.log(uint8String.startsWith('10')); +// expected output: true \ No newline at end of file diff --git a/typedarray-values.js b/typedarray-values.js new file mode 100644 index 0000000..cad95a0 --- /dev/null +++ b/typedarray-values.js @@ -0,0 +1,8 @@ +const uint8 = new Uint8Array([ 10, 20, 30, 40, 50]); +const array1 = uint8.values(); + +array1.next(); +array1.next(); + +console.log(array1.next().value); +// expected output: 30 \ No newline at end of file diff --git a/weakmap-prototype-delete.js b/weakmap-prototype-delete.js new file mode 100644 index 0000000..c3b1821 --- /dev/null +++ b/weakmap-prototype-delete.js @@ -0,0 +1,10 @@ +const weakmap1 = new WeakMap(); +const object1 = {}; + +weakmap1.set(object1, 42); + +console.log(weakmap1.delete(object1)); +// expected output: true + +console.log(weakmap1.has(object1)); +// expected output: false \ No newline at end of file diff --git a/weakmap-prototype-get.js b/weakmap-prototype-get.js new file mode 100644 index 0000000..851805b --- /dev/null +++ b/weakmap-prototype-get.js @@ -0,0 +1,11 @@ +const weakmap1 = new WeakMap(); +const object1 = {}; +const object2 = {}; + +weakmap1.set(object1, 42); + +console.log(weakmap1.get(object1)); +// expected output: 42 + +console.log(weakmap1.get(object2)); +// expected output: undefined \ No newline at end of file diff --git a/weakmap-prototype-has.js b/weakmap-prototype-has.js new file mode 100644 index 0000000..7d1a8e7 --- /dev/null +++ b/weakmap-prototype-has.js @@ -0,0 +1,11 @@ +const weakmap1 = new WeakMap(); +const object1 = {}; +const object2 = {}; + +weakmap1.set(object1, 'foo'); + +console.log(weakmap1.has(object1)); +// expected output: true + +console.log(weakmap1.has(object2)); +// expected output: false \ No newline at end of file diff --git a/weakmap-prototype-set.js b/weakmap-prototype-set.js new file mode 100644 index 0000000..b0ac83c --- /dev/null +++ b/weakmap-prototype-set.js @@ -0,0 +1,12 @@ +const weakmap1 = new WeakMap(); +const object1 = {}; +const object2 = {}; + +weakmap1.set(object1, 'foo'); +weakmap1.set(object2, 'bar'); + +console.log(weakmap1.get(object1)); +//expected output: "foo" + +console.log(weakmap1.get(object2)); +//expected output: "bar" \ No newline at end of file diff --git a/weakset-prototype-add.js b/weakset-prototype-add.js new file mode 100644 index 0000000..bb861f3 --- /dev/null +++ b/weakset-prototype-add.js @@ -0,0 +1,14 @@ +const weakset1 = new WeakSet(); +const object1 = {}; + +weakset1.add(object1); +console.log(weakset1.has(object1)); +// expected output: true + +try { + weakset1.add(1); +} catch(error) { + console.log(error); + // expected output: "Error: Invalid value used in weak set" in Chrome + // expected output: "TypeError: WeakSet value must be an object, got the number 1" in Firefox +} \ No newline at end of file diff --git a/weakset-prototype-delete.js b/weakset-prototype-delete.js new file mode 100644 index 0000000..a520354 --- /dev/null +++ b/weakset-prototype-delete.js @@ -0,0 +1,12 @@ +const weakset1 = new WeakSet(); +const object1 = {}; + +weakset1.add(object1); + +console.log(weakset1.has(object1)); +// expected output: true + +weakset1.delete(object1); + +console.log(weakset1.has(object1)); +// expected output: false \ No newline at end of file diff --git a/weakset-prototype-has.js b/weakset-prototype-has.js new file mode 100644 index 0000000..99f6509 --- /dev/null +++ b/weakset-prototype-has.js @@ -0,0 +1,11 @@ +const weakset1 = new WeakSet(); +const object1 = {}; +const object2 = {}; + +weakset1.add(object1); + +console.log(weakset1.has(object1)); +// expected output: true + +console.log(weakset1.has(object2)); +// expected output: false \ No newline at end of file