Published
Edited
Feb 4, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
convert = input => {
const result = []
let previousChar = null
let currentCount = 0
for (const char of input.split("")) {
if (previousChar && char !== previousChar) {
result.push({ s: previousChar, c: currentCount })
currentCount = 0
}
currentCount += 1
previousChar = char
}
result.push({ s: previousChar, c: currentCount })
return result
}
Insert cell
Insert cell
Insert cell
input.split("").reduce((acc, curr) => {
const head = acc[0] || { s: curr, c: 0 }
const incr = head.s === curr
const next = incr ? { s: head.s, c: head.c + 1 } : { s: curr, c: 1 }
return [next, ...acc.slice(incr ? 1 : 0)]
}, []).reverse()
Insert cell
Insert cell
Insert cell
aq
.table({ s: input.split("") })
.derive({ r: op.rank() })
.derive({ v: d => d.s === op.lead(d.s, 1) ? null : d.r })
.filter(d => d.v !== null)
.derive({ c: d => d.v - (op.lead(d.v, -1) || 0) })
.select("s", "c")
.view()
Insert cell
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