Skip to main content
added 43 characters in body
Source Link
User1974
  • 198
  • 1
  • 19

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

I would be happy to hear comments about anything I might have overlooked.


Related:

I have a related question in the ArcGIS Community that has a GIS-specific script: Set polyline M-values to cumulative length of lineSet polyline M-values to cumulative length of line.

That script is the latest version.

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

I would be happy to hear comments about anything I might have overlooked.


Related:

I have a related question in the ArcGIS Community that has a GIS-specific script: Set polyline M-values to cumulative length of line

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

I would be happy to hear comments about anything I might have overlooked.


Related:

I have a related question in the ArcGIS Community that has a GIS-specific script: Set polyline M-values to cumulative length of line.

That script is the latest version.

added 313 characters in body
Source Link
User1974
  • 198
  • 1
  • 19

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

WouldI would be happy to hear comments about anything I might have overlooked.


Related:

I have a related question in the ArcGIS Community that has a GIS-specific script: Set polyline M-values to cumulative length of line

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

Would be happy to hear comments about anything I might have overlooked.

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

I would be happy to hear comments about anything I might have overlooked.


Related:

I have a related question in the ArcGIS Community that has a GIS-specific script: Set polyline M-values to cumulative length of line

deleted 4 characters in body
Source Link
User1974
  • 198
  • 1
  • 19

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
 
for (var path_idx in paths) {
    var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

Would be happy to hear comments about anything I might have overlooked.

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
 
for (var path_idx in paths) {
    var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

Would be happy to hear comments about anything I might have overlooked.

All of KIKO Software's review applies, but the suggest replacement code doesn't work on the JavaScript implementation being targeted (ArcGIS Arcade), because it doesn't support these keywords:

  • const
  • let
  • for (… of …)

It supports only the keywords mentioned in ArcGIS Arcade - Structure and Logic.


We can modify KIKO Software's code to something compatible:

function pythagoras(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];
var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1]
        length += pythagoras(oldX, oldY, newX, newY);
        paths[path_idx][point_idx][2] = length;
        oldX = newX;
        oldY = newY;
    }
}  
console.log(JSON.stringify(paths));
//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]

JSFiddle

Would be happy to hear comments about anything I might have overlooked.

Correct syntax of for (… of …)
Source Link
Toby Speight
  • 81.7k
  • 14
  • 101
  • 308
Loading
Adapt to make it an actual review (mostly by reference, but...)
Source Link
Toby Speight
  • 81.7k
  • 14
  • 101
  • 308
Loading
added 18 characters in body
Source Link
User1974
  • 198
  • 1
  • 19
Loading
Source Link
User1974
  • 198
  • 1
  • 19
Loading