Skip to content

Instantly share code, notes, and snippets.

@roger-hamilton
Last active September 1, 2016 15:00
Show Gist options
  • Save roger-hamilton/529b9e6b742ce2e202db59f9df798953 to your computer and use it in GitHub Desktop.
Save roger-hamilton/529b9e6b742ce2e202db59f9df798953 to your computer and use it in GitHub Desktop.
Test
import _ from 'lodash';
const syms = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG";
const prob = _([...syms])
.groupBy()
.mapValues('length')
.map((freq, sym) => ({ sym, freq }))
.sortBy('freq')
.reverse()
.map(({ sym, freq }) => ({sym, freq: freq / syms.length}))
.value();
const cumProp = _(prob)
.map(({ sym, freq}, i) => ({sym, range: [prob.slice(0, i).reduce((c, { freq }) => c + freq, 0), freq]}))
.value();
const range = [0, 1];
const toEncode = [..."HELLO WORLD"];
while(toEncode.length) {
const sym = toEncode.shift();
const t = '';
}
// const encode = (sym, freq) => {
// let tot = _.reduce(freq, (sum, c) => sum + c, 0);
// let prob = _.mapValues(freq, f => f / total);
// const range = [0, 1];
// while(sym.length){
// const cur = sym.shift(); ///Removes and Returns the first symbol in sym
// }
// };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment