I can't find this exact algorithm anywhere on the internet. What I'm trying to implement is the following function(adsbygoogle = window.adsbygoogle || []).push({});

in a larger program I'm writing. (I know how to do it easily if the subarrays are contiguous sequences of the original array)Code (Text):

// Returns all subarrays of the given array, not including the empty array

// ex. [a,b,c].subarrays() = [ [a], [b], [c], [a,b], [a,c], [b,c], [a,b,c] ]

Array.prototype.subarrays = function(...)

{

// ..

}

Also, if this makes things easier, in the single use case of my program the original array has unique items.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# JavaScript Algorithm to return all subarrays of a given array

Have something to add?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**