Skip to content Skip to sidebar Skip to footer

Javascript - Use An Array To Calculate Some Coordinates

the line below will return some numbers in the format 8458.268,19166.142,13113.780,25837.795,13113.780,25837.795... output=output.split('\n').filter(/./.test, /Coordinates/).join(

Solution 1:

Try using a map function on the array at the point where you need to make the calculations. Once you have the array so that each item is in the format that you want, you can map through the array and divide each item by 2.2.

E.g.

arr.map((item) => {
  return item/2.2;
}) // at this point you could chain on 'join("\n")' or whatever

If I'm understanding you correctly, you want to make an array out of the data you have, then perform a calculation on each piece of that data, and then do something else with it. If so, then the built in javascript map function is the way to go.

Note: I use ES6 fat arrow syntax for the function inside map, obviously you could just use an anonymous function with map(function(item) {...});

Post a Comment for "Javascript - Use An Array To Calculate Some Coordinates"