E
E
eugenedrvnk2019-06-21 13:25:51
JavaScript
eugenedrvnk, 2019-06-21 13:25:51

How to get all possible combinations of shuffling the digits of a number?

There is, for example, the number 941.
At the output, you need to get: 941, 914, 491, 419, 149, 194.
Judging by the materials in other intersecting topics on the Internet, it is necessary to use recursion here, but how to apply it, I still have an option in my head is not coming.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
longclaps, 2019-06-21
@eugenedrvnk

function* permutatins(s) {
    if (s.length > 1)
        for (let i = 0; i < s.length; i++)
            for (let t of permutatins(s.slice(0, i) + s.slice(i + 1)))
                yield s.charAt(i) + t;
    else yield s;
}

for (let s of permutatins('941'))
    console.log(s);

A
Anton Fedoryan, 2019-06-21
@AnnTHony

Iterating over combinations of array elements

A
aol-nnov, 2017-08-16
@aol-nnov

You make your own WebViewClient, override shouldOverrideUrlLoading and onLoadResource in it.
well, you register it in webview through setWebViewClient.
in onLoadResource you open a new activity.

D
Dmitry, 2017-08-16
@R4UAB

If possible, can you elaborate on an example?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question