So far: Bubble sort, select sort, copy array, find random number, delete blank text child node, boundless drag and bounded drag, prevent drag default behavior;

Bubble Sort (from small to large)

function bubbleSortSmallToBig(arr){ for(var i = 1; i < arr.length; i ++){ for(var j = 0; j < arr.length - i; j ++){ if(arr[j] > arr[j + 1]){ var t = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = t; } } } return arr; }Copy the code

Bubble Sort (from large to small)

function bubbleSortBigToSmall(arr){ for(var i = 1; i < arr.length; i ++){ for(var j = 0; j < arr.length - i; j ++){ if(arr[j] < arr[j + 1]){ var t = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = t; } } } return arr; }Copy the code

Selection sort (from small to large)

function selectionSmallToBig(arr){ for(var i = 0; i < arr.length - 1; i ++){ for(var j = i + 1; j < arr.length; j ++){ if(arr[i] > arr[j]){ var t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } } return arr; }Copy the code

Selection sort (from largest to smallest)

function selectionBigToSmall(arr){ for(var i = 0; i < arr.length - 1; i ++){ for(var j = i + 1; j < arr.length; j ++){ if(arr[i] < arr[j]){ var t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } } return arr; }Copy the code

Copy array 1

function copyArr(arr){return arr.slice(0); }Copy the code

Copy array 2

function copyArr01(arr){return arr.concat(); }Copy the code

Copy array 3

function copyArr02(arr){ var list = []; for(var i = 0,len = arr.length; i < len; i ++){ list.push(arr[i]); } return list; }Copy the code

Finding random integers

function randomInt(min,max){
    if(min > max){
        var t = min;
        min = max;
        max = t;
    }
    return Math.floor(Math.random() * (max - min + 1) + min);
}
Copy the code

Delete the blank text child node

function removeSpace(node){ var childs = node.childNodes; for(var i = 0; i < childs.length; i ++){ if(childs[i].nodeType === 3 && /^\s+$/.test(childs[i].nodeValue)){ node.removeChild(childs[i]); } } return node; }Copy the code

Borderless drag

function drag(id){
    var ele = document.getElementById(id);
    ele.onmousedown = function(evt){
        var e = evt || window.event;
        var disX = e.offsetX;
        var disY = e.offsetY;
        document.onmousemove = function(evt){
            var e = evt || window.event;ele.style.left = e.pageX - disX + 'px';
            ele.style.top = e.pageY - disY + 'px';
        }
    document.onmouseup = function(){
        document.onmousemove = null;
    }
}
Copy the code

Prevents the default behavior of drag and drop

document.ondragstart = function(){return false; }}}Copy the code

Drag with boundaries

function dragWidthBorder(id){ var ele = document.getElementById(id); ele.onmousedown = function(evt){ var e = evt || window.event; var disX = e.offsetX; var disY = e.offsetY; document.onmousemove = function(evt){ var e = evt || window.event; var left = e.pageX - disX; var top = e.pageY - disY; If (left <= 0){left = 0; //clientWidth : Visual width} else if (left > = document. DocumentElement. ClientWidth - ele. OffsetWidth) {/ left/right border = document.documentElement.clientWidth - ele.offsetWidth; } if(top <= 0){top = 0; } else if (top > = document. DocumentElement. ClientHeight - ele. OffsetHeight) {/ / the top border = document.documentElement.clientHeight - ele.offsetHeight; } ele.style.left = left + 'px'; ele.style.top = top + 'px'; } document.onmouseup = function(){document.onmousemove = null; }}}Copy the code

Prevents the default behavior of drag and drop

document.ondragstart = function(){return false; }}}Copy the code