-
-
Notifications
You must be signed in to change notification settings - Fork 442
Closed
Labels
E-MediumMedium difficulty problemMedium difficulty problemHacktoberfestHacktoberfest 2021 - https://hacktoberfest.digitalocean.comHacktoberfest 2021 - https://hacktoberfest.digitalocean.comenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Milestone
Description
ECMASCript feature
Set objects are collections of ECMAScript language values. A distinct value may only occur once as an element of a Set's collection. Distinct values are discriminated using the SameValueZero comparison algorithm.
I would like to see Set
implemented. ECMAScript specification.
Example code
let mySet = new Set()
mySet.add(1) // Set [ 1 ]
mySet.add(5) // Set [ 1, 5 ]
mySet.add(5) // Set [ 1, 5 ]
mySet.add('some text') // Set [ 1, 5, 'some text' ]
let o = {a: 1, b: 2}
mySet.add(o)
mySet.add({a: 1, b: 2}) // o is referencing a different object, so this is okay
mySet.has(1) // true
mySet.has(3) // false, since 3 has not been added to the set
mySet.has(5) // true
mySet.has(Math.sqrt(25)) // true
mySet.has('Some Text'.toLowerCase()) // true
mySet.has(o) // true
mySet.size // 5
mySet.delete(5) // removes 5 from the set
mySet.has(5) // false, 5 has been removed
mySet.size // 4, since we just removed one value
console.log(mySet)
// logs Set(4) [ 1, "some text", {…}, {…} ] in Firefox
// logs Set(4) { 1, "some text", {…}, {…} } in Chrome
Example to work from
Array is implemented here: https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/array/mod.rs
Contributing
https://github.com/jasonwilliams/boa/blob/master/CONTRIBUTING.md
Metadata
Metadata
Assignees
Labels
E-MediumMedium difficulty problemMedium difficulty problemHacktoberfestHacktoberfest 2021 - https://hacktoberfest.digitalocean.comHacktoberfest 2021 - https://hacktoberfest.digitalocean.comenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers