fork download
  1. const task = (n) => {
  2. const points = [];
  3. const linesArr = [];
  4.  
  5. dotGen(n);
  6. mkLine(points);
  7. linesArr.map(lineLength);
  8. const avg = linesArr.reduce((a, b) => a.len + b.len) / linesArr.length;
  9. console.log(linesArr);
  10. console.log(avg);
  11.  
  12. function dotGen(n) {
  13. for (let i = 1; i <= n; i++) {
  14. points.push({
  15. x: Math.random(),
  16. y: Math.random()
  17. })
  18. }
  19. }
  20.  
  21. function mkLine(points) {
  22. for (let i = 0; i < points.length - 1; i++) {
  23. for (let j = i + 1; j < points.length; j++) {
  24. linesArr.push({
  25. start: {
  26. x: points[i].x,
  27. y: points[i].y
  28. },
  29. end: {
  30. x: points[j].x,
  31. y: points[j].y
  32. },
  33. len: 0
  34. })
  35. }
  36. }
  37. }
  38.  
  39. function lineLength(line) {
  40. line.len = Math.sqrt((line.end.x - line.start.x) ** 2 + (line.end.y - line.start.y) ** 2)
  41. }
  42.  
Runtime error #stdin #stdout #stderr 0s 106240KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:40:58 SyntaxError: syntax error:
prog.js:40:58         line.len = Math.sqrt((line.end.x - line.start.x) ** 2 + (line.end.y - line.start.y) ** 2)
prog.js:40:58 ..........................................................^