MCPcopy Index your code
hub / github.com/easydiffusion/easydiffusion / permute

Function permute

ui/media/js/utils.js:157–179  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

155
156
157function permute(arr) {
158 let permutations = []
159 let n = arr.length
160 let n_permutations = Math.pow(2, n)
161 for (let i = 0; i < n_permutations; i++) {
162 let perm = []
163 let mask = Number(i)
164 .toString(2)
165 .padStart(n, "0")
166
167 for (let idx = 0; idx < mask.length; idx++) {
168 if (mask[idx] === "1" && arr[idx].trim() !== "") {
169 perm.push(arr[idx])
170 }
171 }
172
173 if (perm.length > 0) {
174 permutations.push(perm)
175 }
176 }
177
178 return permutations
179}
180
181function permuteNumber(arr) {
182 return Math.pow(2, arr.length)

Callers 1

permutePromptsFunction · 0.85

Calls 2

toStringMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected