티스토리 뷰

Inmutable Push

function immutablePush(arr, newEntry){ return [ ...arr, newEntry ] }

Inmutable Pop

function immutablePop(arr){ return arr.slice(0, -1) }

Inmutable Unshift

function immutableUnshift(arr, newEntry){ return [ newEntry, ...arr ] }

Sort

function immutableSort(arr, compareFunction) {
return [ ...arr ].sort(compareFunction)
}
// or...
function immutableSort(arr, compareFunction) {
return arr.slice().sort(compareFunction)
}

Reverse

function immutableSort(arr, compareFunction) {
return [ ...arr ].reverse()
}
// or...
function immutableSort(arr, compareFunction) {
return arr.slice().reverse()
}

Splice

// ES6
function immutableSplice(arr, start, deleteCount, ...items) {
return [ ...arr.slice(0, start), ...items, ...arr.slice(start + deleteCount) ]
}

Delete

function immutableDelete (arr, index) {
return arr.slice(0,index).concat(arr.slice(index+1))
}

 

reference

 

 

 

'프로그래밍 언어 > javascript' 카테고리의 다른 글

javascript(nodejs) 순환참조 해결하기  (0) 2020.11.17
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/04   »
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
글 보관함