let arr = [123, 12, 32, 14,122,4,6,8,12]
function bubble(arr) {
for(let i = 0; i < arr.length; i++ ) {
for(let k = 0; k < arr.length; k++) {
let temp = 0
if(arr[k] > arr[k+1]) {
temp = arr[k]
arr[k] = arr[k+1]
arr[k+1] = temp
}
}
}
return arr
}
function quick(arr) {
if(arr.length < 2) {
return arr
}
let mid = arr[Math.floor(arr.length / 2)]
let left = []
let right = []
arr.splice(Math.floor(arr.length / 2), 1)
arr.map(item => {
if(item < mid) {
left.push(item)
} else {
right.push(item)
}
})
return quick(left).concat(mid,quick(right))
}
function insert(arr) {
if (!arr || arr.length < 2 ) {
return arr
}
let newArr = [arr[0]]
for(let i = 0; i < arr.length; i++) {
if (arr[i] < newArr[0]) {
newArr.unshift(arr[i])
continue
}
for(let k = newArr.length - 1; k >= 0; k--) {
if (arr[i] > newArr[k]) {
newArr.splice(k + 1, 0, arr[i])
break
}
}
}
return newArr
}
function long(arr) {
let repeatIndex = -1
let max = 0
for(let i = 0; i < arr.length; i++) {
for (let k = i - 1; k >= 0; k--){
if (arr[i] === arr[k]) {
if (repeatIndex < k) {
repeatIndex = k
}
}
}
if (max < i - repeatIndex) {
max = i -repeatIndex
}
}
return max
}
console.log(long(arr))
function mybind(obj = window){
let _this = this
return function (...args){
_this.call(obj,...args)
}
}
console