I need a Set that has the API similar to the Set in Java.
This implementation:
.html
Requires the use of RequireJS, which requires my Java brain to twist too much at the moment.
Posting a function that is the functionality for Set would be a great answer. Or a link to a Google Set or some other tech giant who has created this code already.
What about Google's Closure? The name confused me but it has a set.
I need a Set that has the API similar to the Set in Java.
This implementation:
http://jsclass.jcoglan./set.html
Requires the use of RequireJS, which requires my Java brain to twist too much at the moment.
Posting a function that is the functionality for Set would be a great answer. Or a link to a Google Set or some other tech giant who has created this code already.
What about Google's Closure? The name confused me but it has a set.
Share Improve this question edited Nov 7, 2013 at 3:19 Kevin Panko 8,56419 gold badges51 silver badges63 bronze badges asked Nov 7, 2013 at 1:40 Guido AnselmiGuido Anselmi 3,9228 gold badges37 silver badges58 bronze badges1 Answer
Reset to default 10In my opinion whatever java.util.Set can achieve can be done using simple javascript object. I don't see why you need additional library:
// empty set
var basket = {};
// adding object to set
basket['apple'] = true;
basket['banana'] = true;
basket['orange'] = true;
basket['apple'] = true;
// iterating through set contents, should print:
// apple
// banana
// orange
for(var fruit in basket)
console.log(fruit);
// check if an element exist
if(basket['pineapple']) {
console.log('has pineapple');
} else {
console.log('no pineapple');
}
// remove element from set
delete basket['apple'];