codehire cup practice 2 JS
http://blog.codehire.com/2013/06/04/solutions-to-codehire-cup-2012-preliminary-round-challenge-ruby
by michaeldausmann
JavaScript
var angles = {N:0, NE:45, E:90, SE:135, S:180, SW:225, W:270, NW:315};
var input = '(A:B)[N:100],(B:C)[NW:50],(C:D)[E:75]'
var point, x=0, y=0;
var myRegexp = /\[(.*?):(.*?)\]/g;
while(point = myRegexp.exec(input))
{
var angle = angles[point[1]] / (180/Math.PI);
x+= Math.sin(angle) * point[2];
y+= Math.cos(angle) * point[2];
}
console.log(Math.round(Math.sqrt(x * x + y * y)));