
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to find all subsets of a set in JavaScript?
To find all subsets of a set, use reduce() along with map() in JavaScript. Let’s say, we are passing the set [8,9] and finding the subsets.
Example
const findAllSubsetsoOfGivenSet = originalArrayValue => originalArrayValue.reduce( (givenSet, setValue) => givenSet.concat( givenSet.map(givenSet => [setValue,...givenSet]) ), [[]] ); console.log(findAllSubsetsoOfGivenSet([8,9]));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo36.js.
Output
This will produce the following output.
PS C:\Users\Amit\JavaScript-code> node demo36.js [ [], [ 8 ], [ 9 ], [ 9, 8 ] ]
- Related Articles
- Find all distinct subsets of a given set in C++
- List all the subsets of a set {m , n}
- Print all subsets of given size of a set in C++
- Python program to get all subsets of given size of a set
- Golang program to find all subsets of a string
- Python program to get all subsets of a given size of a set
- Java Program To Find all the Subsets of a String
- Finding all possible subsets of an array in JavaScript
- C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
- Sum of all subsets of a set formed by first n natural numbers
- C++ Program to Generate All Pairs of Subsets Whose Union Make the Set
- Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers
- Find all disjointed intersections in a set of vertical line segments in JavaScript
- How to remove all the elements from a set in javascript?
- Count number of ways to partition a set into k subsets in C++

Advertisements