Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript Set Intersection Operation

// perform intersection operation
// elements of set a that are also in set b
function intersection(setA, setB) {
    let intersectionSet = new Set();

    for (let i of setB) {
        if (setA.has(i)) {
            intersectionSet.add(i);
        }
    }
    return intersectionSet;
}
// two sets of fruits
let setA = new Set(['apple', 'mango', 'orange']);
let setB = new Set(['grapes', 'apple', 'banana']);

let result = intersection(setA, setB);

console.log(result);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use radio buttons in react class-based components 
Javascript :: js date get hours 
Javascript :: index of an element 
Javascript :: JavaScript .clearRect 
Javascript :: reverse array js 
Javascript :: js reverse linked list 
Javascript :: us postal code regex 
Javascript :: “javascript remove last element from array 
Javascript :: prevent redirect javascript 
Javascript :: run code snippet 
Javascript :: falsy values in javascript 
Javascript :: secure cookie in javascript 
Javascript :: react router lazy load 
Javascript :: jsx loop array 
Javascript :: html content in jspdf 
Javascript :: post api in next.js 
Javascript :: jquery get text of element without child elements 
Javascript :: javascript style guide 
Javascript :: uuid in node js 
Javascript :: How do I redirect to another webpage using javascript 
Javascript :: Define the constructor property on the Dog prototype. 
Javascript :: string length in javascript 
Javascript :: use theme in component mui 
Javascript :: how to update node in terminal 
Javascript :: nestjs allow origin 
Javascript :: react iterate over map 
Javascript :: check a date is between two dates in javascript 
Javascript :: jquery datepicker 
Javascript :: js date to timestamp 
Javascript :: js search in object 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =