Input: arr = [3,8,-10,23,19,-4,-14,27]
Output: [[-14,-10],[19,23],[23,27]]
배열 중 가장 차가 적은 배열 쌍을 오름차순으로 반환
var minimumAbsDifference = function(arr) {
const ascend=arr.sort((a,b)=>a-b)
const diff=[]
const result=[]
for(let i=0;i<arr.length-1;i++){
diff.push(ascend[i+1]-ascend[i])
}
const min=Math.min(...diff)
for(let i=0;i<arr.length-1;i++){
if(ascend[i+1]-ascend[i] === min){
result.push([ascend[i+1],ascend[i]].sort((a,b)=>a-b))
}
}
return result
};
const ascend=arr.sort((a,b)=>a-b)
const diff=[]
for(let i=0;i<arr.length-1;i++){
diff.push(ascend[i+1]-ascend[i])
}
const min=Math.min(...diff)
const result=[]
for(let i=0;i<arr.length-1;i++){
if(ascend[i+1]-ascend[i] === min){
result.push([ascend[i+1],ascend[i]].sort((a,b)=>a-b))
}
}
return result