I'm trying to compare two arrays with different lengths and that the non-repeating values are added to a new array.
I would like to know how I do it, then I share my code:
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope, $rootScope) {
$rootScope.res=[];
$scope.Array1 = [
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "05-04-2016"
},
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "12-04-2016"
},
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "19-04-2016"
},
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "26-04-2016"
},
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "03-05-2016"
},
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "10-05-2016"
},
{
"responsable": "S/N",
"tipo": "S/N",
"guid": "a7c2dd58-eb27-004e-e043-ac10360d004e",
"nivel": "PREGRADO",
"fecha_clase": "17-05-2016"
}
];
$scope.Array2=[{"fecha":"05-04-2016"},{"fecha":"12-04-2016"},{"fecha":"19-04-2016"},{"fecha":"26-04-2016"},{"fecha":"03-05-2016"},{"fecha":"10-05-2016"},{"fecha":"17-05-2016"},{"fecha":"24-05-2016"},{"fecha":"31-05-2016"},{"fecha":"07-06-2016"},{"fecha":"14-06-2016"},{"fecha":"21-06-2016"},{"fecha":"28-06-2016"},{"fecha":"05-07-2016"},{"fecha":"12-07-2016"},{"fecha":"19-07-2016"},{"fecha":"26-07-2016"},{"fecha":"02-08-2016"}];
for(var a=0;a<$scope.Array2.length;a++){
for(var b=0;b<$scope.Array1.length;b++){
var fechasLista=$scope.Array1[b].fecha_clase;
var fechaConvertida =$scope.Array2[a].fecha;
if(fechasLista != fechaConvertida){
//aqui es donde deseo que los valores que no estan repetidos se agreguen en $rootScope.res
$rootScope.res.push({r:'no repetidos '+fechaConvertida});
}
}
}
}
finally I present them in the following way:
<div ng-controller="MyCtrl">
<div ng-repeat="r in res">
{{r.r}}
</div>
</div>
I hope you can help me. Thank you in advance