Learning JavaScript Data Structures and Algorithms by Loiane Groner
Author:Loiane Groner
Language: eng
Format: mobi, epub, pdf
Publisher: Packt Publishing
Published: 2014-10-26T22:00:00+00:00
var values = this.values();
for (var i=0; i<values.length; i++){ //{2}
if (otherSet.has(values[i])){ //{3}
intersectionSet.add(values[i]); //{4}
}
}
return intersectionSet;
}
For the intersection method, we need to find all elements from the current instance of the Set class that also exist in the given Set instance. So first, we create a new Set instance so that we can return it with the common elements (line {1}). Next, we iterate through all the values of the current instance of the Set class (line {2}) and we verify that the value exists in the otherSet instance as well (line {3}). We can use the has method that we implemented earlier in this chapter to verify that the element exists in the Set instance. Then, if the value exists in the other Set instance also, we add it to the created intersectionSet variable (line {4}) and return it.
Let's do some testing:
var setA = new Set();
setA.add(1);
setA.add(2);
setA.add(3);
Download
Learning JavaScript Data Structures and Algorithms by Loiane Groner.epub
Learning JavaScript Data Structures and Algorithms by Loiane Groner.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
ActiveX | ASP.NET |
Cold Fusion | CSS |
DHTML | Java Server Pages |
JavaScript | PHP |
Python | Ruby |
XSL |
Hello! Python by Anthony Briggs(9901)
The Mikado Method by Ola Ellnestam Daniel Brolund(9767)
Dependency Injection in .NET by Mark Seemann(9325)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7769)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7548)
Svelte with Test-Driven Development by Daniel Irvine(7073)
Test-Driven Development with PHP 8 by Rainier Sarabia(6799)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6666)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6529)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6397)
Web Development with Django by Ben Shaw Saurabh Badhwar(6132)
React Application Architecture for Production by Alan Alickovic(5852)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5801)
Kotlin in Action by Dmitry Jemerov(5047)
Audition by Ryu Murakami(4580)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4405)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4312)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4256)
Functional Programming in JavaScript by Mantyla Dan(4035)
