Javascript | Set all values of an array

前端 未结 8 857
清酒与你
清酒与你 2020-12-29 19:45

Code

var cool = new Array(3);
cool[setAll] = 42; //cool[setAll] is just a pseudo selector..
alert(cool);

Result

8条回答
  •  一生所求
    2020-12-29 20:01

    Found this while working with Epicycles - clearly works - where 'p' is invisible to my eyes.

    /** Convert a set of picture points to a set of Cartesian coordinates */
    function toCartesian(points, scale) {
      const x_max = Math.max(...points.map(p=>p[0])),
      y_max = Math.max(...points.map(p=>p[1])),
      x_min = Math.min(...points.map(p=>p[0])),
      y_min = Math.min(...points.map(p=>p[1])),
      signed_x_max = Math.floor((x_max - x_min + 1) / 2),
      signed_y_max = Math.floor((y_max - y_min + 1) / 2);
    
      return points.map(p=>
      [ -scale * (signed_x_max - p[0] + x_min),
      scale * (signed_y_max - p[1] + y_min) ] );
    }
    

提交回复
热议问题