Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arr = ["0000a59e6c8c812bf11c1ffe","00e9620d5d48ad32a66e787f"];
- var l = arr[0].length
- var avg = (val) => val.reduce((sum, v) => sum + v, 0) / val.length;
- var std = val => {
- const µ = avg(val);
- const addedSquareDiffs = val
- .map(val => val - µ)
- .map(diff => diff ** 2)
- .reduce((sum, v) => sum + v, 0);
- const variance = addedSquareDiffs / (val.length - 1);
- return Math.sqrt(variance);
- };
- var cor = (x,y) => {
- const µ = { x: avg(x), y: avg(y) };
- const s = { x: std(x), y: std(y) };
- const addedMultipliedDifferences = x
- .map((val, i) => (val - µ.x) * (y[i] - µ.y))
- .reduce((sum, v) => sum + v, 0);
- const dividedByDevs = addedMultipliedDifferences / (s.x * s.y);
- return dividedByDevs / (x.length - 1);
- };
- arr = arr.map(e=>e.split("").map(e=>e.charCodeAt(0)))
- var tArr = [...Array(l)].map((_,i)=>arr.map(e=>e[i]))
- for (let i = 0; i < tArr.length; i++) {
- for (let j = i+1; j < tArr.length; j++) {
- const res = cor(tArr[i],tArr[j])
- console.log({i,j,res})
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement