Full permutation is realized by JS

function permutations(string) {
  return (string.length == 1) ? [string] : string.split("").map(
     (e, i) => permutations(string.slice(0,i) + string.slice(i+1)).map((e2) => e+e2)
  ).reduce((r,e) => r.concat(e)).sort().filter((e,i,a) => (i==0) || a[i-1] != e);
}

is there any boss who can order it? I don"t understand this code

Jun.21,2022

first of all, you have to understand the functions of map reduce concat sort filter in the JS array. It is recommended that you check the MDN website

.

in addition, it is not recommended to use this style of code in the project, because the readability is too poor, almost zero, if others take over your project to see this kind of code, they will probably scold their mother.

it is recommended to write

in several steps.
function permutations(string) {
    if (string.length == 1) {
        return [string]
    } else {
        const arry = string.split('') 
        arry.map((e, i) => {
            let newString = string.slice(0,i) + string.slice(i+1)
            // 
            permutations(newString).map((e2) => e+e2)
        })
        .reduce((r,e) => r.concat(e))
        .sort()
        .filter((e,i,a) => (i==0) || a[i-1] != e)
    }
}

it's OK to change it like this. You should be able to see the idea of this code clearly. However, the performance of this function is too poor, it is not recommended to write this way.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea7cfc-1e87.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea7cfc-1e87.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?