-
Notifications
You must be signed in to change notification settings - Fork 0
/
diffSort.js
47 lines (30 loc) · 876 Bytes
/
diffSort.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const sort = (postion, length, arr) => {
if(Array.isArray(arr)) {
arr.map(item => {
const obj = Object.create(null)
obj.value = item
obj.sonVal = []
let index = 1
while(index <= item) {
if(item % index === 0) {
obj.sonVal.push(index)
index++
}
}
return obj
})
arr.sort((pre, next) => {
const preLen = pre.sonVal.length
const nextLen = next.sonVal.length
if (preLen !== nextLen) {
return preLen - nextLen
}
return pre.value - next.value
})
return arr[postion].value
}
}
const postion = 4
const length = 6
const arr = [1,2,3,4,5,6]
console.log(sort(postion, length, arr))