This Gist was automatically created by Carbide, a free online programming environment.
Last active
September 1, 2016 15:00
-
-
Save roger-hamilton/529b9e6b742ce2e202db59f9df798953 to your computer and use it in GitHub Desktop.
Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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