Advertisement
x7f

Untitled

x7f
Feb 24th, 2022
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var arr = ["0000a59e6c8c812bf11c1ffe","00e9620d5d48ad32a66e787f"];
  2. var l = arr[0].length
  3.  
  4. var avg = (val) => val.reduce((sum, v) => sum + v, 0) / val.length;
  5. var std = val => {
  6.   const µ = avg(val);
  7.   const addedSquareDiffs = val
  8.     .map(val => val - µ)
  9.     .map(diff => diff ** 2)
  10.     .reduce((sum, v) => sum + v, 0);
  11.   const variance = addedSquareDiffs / (val.length - 1);
  12.   return Math.sqrt(variance);
  13. };
  14. var cor = (x,y) => {
  15.   const µ = { x: avg(x), y: avg(y) };
  16.   const s = { x: std(x), y: std(y) };
  17.   const addedMultipliedDifferences = x
  18.     .map((val, i) => (val - µ.x) * (y[i] - µ.y))
  19.     .reduce((sum, v) => sum + v, 0);
  20.   const dividedByDevs = addedMultipliedDifferences / (s.x * s.y);
  21.   return dividedByDevs / (x.length - 1);
  22. };
  23.  
  24. arr = arr.map(e=>e.split("").map(e=>e.charCodeAt(0)))
  25. var tArr = [...Array(l)].map((_,i)=>arr.map(e=>e[i]))
  26.  
  27. for (let i = 0; i < tArr.length; i++) {
  28.   for (let j = i+1; j < tArr.length; j++) {
  29.     const res = cor(tArr[i],tArr[j])
  30.     console.log({i,j,res})
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement