i have a table of CItyDistance: CIty1Id|City2Id|Distance(KM), Now in my project i receive 2 cities Id's, i want to check if there is a calculated distance for these 2 cities.
so it doesn't matter who will be City1 Or City2 , i need to check both options. The way that i found to check it is too long and messy. Can anyone offer an alternative? (Please check Plunker Example: https://plnkr.co/edit/nzB8zy0034LqJFgL8qk7?p=preview
$scope.CompanyCity = { Id: 59, Name: 'berline' };
$scope.result = "";
$scope.distances = [
{city1: 59,city2: 1, Distance: 50 },
{city1: 1, city2: 58, Distance: 80 },
{city1: 3, city2: 59, Distance: 25 },
{city1: 4, city2: 1, Distance: 120 }];
$scope.findDistance = function(studentCityID) {
angular.forEach($scope.distances, function(value, key) {
if (value.city1 == studentCityID && value.city2 == $scope.CompanyCity.Id) {
$scope.result = value.Distance;
}
else if (value.city2 == studentCityID && value.city1 == $scope.CompanyCity.Id) {
$scope.result = value.Distance;
}
});
};
$scope.findDistance(1);