Js in the original array based on every 3 values to form a new array, the values inside can not be repeated, how to combine?

js forms a new array every 3 values based on the original array, and the values in it cannot be repeated

.

primitive array

var result = [];
$.each(arr,function(i){
            var newArr = [];
            newArr.push(arr[i]);
            for(var a=i; a<arrLength; aPP){
                    newArr.push(arr[a]);
                    if(arr[a+1]){
                        newArr.push(arr[a+1]);
                    }
                if(newArr.length == 3){
                    result.push(newArr);
                }
            }
        });

        console.log(result);
Apr.30,2021

Classical combinatorial problem. Sort first, then dfs + backtracking and finally judge the length.

  

Combinatorial problem. Write or find a combination library. For loop is not universal

Menu