import type { SortOpts , Transducer } from "./api.js" ; import { comp } from "./comp.js" ; import { __sortOpts } from "./internal/sort-opts.js" ; import { __iter } from "./iterator.js" ; import { map } from "./map.js" ; import { partition } from "./partition.js" ; /**
 * Transducer. Similar to  {@link (movingAverage:1)} , but yields median
 * of sliding window and supports non-numeric inputs.
 *
 *  remarks param n param opts param src export function movingMedian < A , B > ( n , opts ? ) ; export function movingMedian < A , B > ( n , src ) ; export function movingMedian < A , B > ( n , opts , src ) ; export function movingMedian < A , B > ( ... args ) { const iter = __iter ( movingMedian , args ) ; if ( iter ) { return iter ; } const { key , compare } = __sortOpts < A , B > ( args [ 1 ] ) ; const n = args [ 0 ] ; const m = n >> 1 ; return comp < A , A [ ] , A > ( partition ( n , 1 , true ) , map ( ( window ) => window . slice ( ) . sort ( ( a , b ) => compare ( key ( a ) , key ( b ) ) ) [ m ] ) ) ; }