портирование функции
здравствуйте. подскажите, как более понятно переписать функцию
indexElementMatchingFunction. Не очень понятно, как передать функцию Apoint. function grep (a, b, c) { var d, e = [], f = 0, g = a.length; c = false; for (; f < g; f++) d = !!b(a[f], f), c !== d && e.push(a[f]); return e } function filterFirstMatchingElement(array, fn) { var element = grep(array, fn)[0]; return element; } function indexElementMatchingFunction(array, fn) { var element = filterFirstMatchingElement(array, fn); return array.indexOf(element); } function pointsEqual(currentPoint, Apoint) { return false; // may be true } currentIndex = indexElementMatchingFunction(currentPolygon, function(Apoint) { return pointsEqual(currentPoint, Apoint); }); |
Описание функции pointsEqual
function pointsEqual(point1, point2) { if (!point1) return false; if (!point2) return false; // return point1.x == point2.x && point1.y == point2.y; return numbersEqual(pointsDistance(point1, point2), 0); } function numbersEqual(num1, num2) { return Math.abs(num2 - num1) < 1e-14; } function pointsDistance(point1, point2) { return Math.pow(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2), 0.5); } |
Это замыкание. Как его обойти?
|
все решил, можно тему закрывать
|
Часовой пояс GMT +3, время: 00:13. |