Published
Edited
Jul 23, 2022
1 fork
1 star
Insert cell
# Merge Sort
Insert cell
items = [2, 1, 22, 7, 14, 55, 53, 0]
Insert cell
Insert cell
function mergeSort(arr) {
if (arr.length > 1) {
let mid = Math.floor(arr.length/2)
let left = arr.slice(0, mid)
let right = arr.slice(mid, arr.length)
let leftSorted = mergeSort(left)
let rightSorted = mergeSort(right)
let res = mergeArrays(leftSorted, rightSorted)

return res
}

return arr
}
Insert cell
mergeSort(items)
Insert cell
items
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more