var 16 var var function sort for var length-1 var max var for var leng

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var a = [1, 16, 2];
var b = [5, 3, 9];
var s = 0;
function sort(a) {
for (var i = 0; i < a.length-1; i++) {
var max = a[i];
var k = i;
for (var j = i; j < a.length; j++) {
if( max < a[j]){
max = a[j];
k = j;
}
}
a[i] = a[i] + a[k];
a[k] = a[i] - a[k];
a[i] = a[i] - a[k];
}
return a;
}
for(var i = 0; i <n; i++){
s+=a[i]*b[i];
}
console.log(s);