javascript - Looking inefficiencies in a JS function -
i'm working out codeeval problem gives me array of strings. each string has 4 integer values represent 2 points on cartesian grid so, 'a, b, x, y', may same. objective determine relative direction of second point in relation first point , express relationship in conventional orienteering terms, e.g., n, ne, e, ..., nw. if points identical, return here.
i able solve problem ok, , core of function here
var ary = line.split(' '), direction = '', dif_long = ary[2] - ary[0], dif_lat = ary[3] - ary[1]; if (dif_lat !== 0){direction = (dif_lat > 0) ? 'n' : 's';} if (dif_long !== 0){direction += (dif_long > 0) ? 'e' : 'w';} if (direction == '') {direction = 'here';} console.log(direction );
i've put sample data on js fiddle, modified generate list rather console.log.
my problem got 0 points solution. leads me think have performance problem somewhere. appreciate constructive suggestions on eliminating inefficiency.
edit: not class assignment. codeeval.com code challenge site. it's not matter of being correct. it's correct, otherwise site won't score solution.
Comments
Post a Comment