@calipsa/video-utils
Version:
Video utilities
21 lines (16 loc) • 437 B
text/typescript
import { range } from 'lodash'
export default <T>(arr: readonly T[], newSize: number) => {
if (newSize < 1) {
return []
}
if (arr.length <= newSize) {
return arr.slice()
}
if (newSize === 1) {
const midIndex = arr.length - 1 >> 1
return [arr[midIndex]]
}
const ratio = (arr.length - 1) / (newSize - 1)
const indices = range(newSize).map(i => Math.round(i * ratio))
return indices.map(i => arr[i])
}