Convert all frequencies to nearest smaller even values .
let arr1 = [ ] ; for ( let [ key , value ] of freq_2 . entries ( ) ) arr1 . push ( key * Math . floor ( freq_2 . get ( key ) / 2 ) * 2 ) ; arr1 . sort ( function ( a , b ) { return a - b ; } ) ;