getting RangeError: Maximum call stack size exceeded because of recursion in function aStar()