Here is a quick sample to sort to arrays.
(function myFunction2() {
Array.prototype.SumArray = function (arr) {
var arraytotal = [];
if (arr != null && this.length == arr.length) {
for (var i = 0; i < arr.length; i++) {
arraytotal.push(this[i] + arr[i]);
}
}
return arraytotal;
}
Array.prototype.MinIndex = function(arr){
let sortedArray = [];
if (arr != null){
let joinedArray = this.concat(arr);
do {
let minIndx = 0;
for (let i = 0; i < joinedArray.length; i++){
minIndx = joinedArray[i] < joinedArray[minIndx] ? i : minIndx;
}
sortedArray.push(joinedArray[minIndx]);
joinedArray.splice(minIndx, 1);
} while(joinedArray.length > 0);
}
return sortedArray;
}
})();
var array1 = [1, 9, 10, 6];
var array2 = [9, 6, 7, 8];
var arraytotal = array1.SumArray(array2);
let sortedArray = array1.MinIndex(array2);
document.getElementById("demo").innerHTML = `total: ${arraytotal} sorted: ${sortedArray}`;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…