Skip to content

Commit

Permalink
refactor: [DHIS2-14190] account for holes in the options array
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip authored Aug 4, 2023
1 parent 7f69cad commit 73245e0
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions d2-tracker/dhis2.angular.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,13 @@ var d2Services = angular.module('d2Services', ['ngResource'])
const keyString = String(key);

// is key a name?
for(var i=0; i<options.length; i++){
if( keyString === options[i].displayName){
return options[i].code;
}
const option = options.find(option => keyString === option.displayName);
if (option) {
return option.code;
}
// is key a code?
for(var i=0; i<options.length; i++){
if( keyString === options[i].code){
return key;
}
if (options.find(option => keyString === option.code)) {
return key;
}
// not a part of the option set
return null;
Expand All @@ -474,16 +471,13 @@ var d2Services = angular.module('d2Services', ['ngResource'])
const keyString = String(key);

// is key a code?
for(var i=0; i<options.length; i++){
if( keyString === options[i].code){
return options[i].displayName;
}
const option = options.find(option => keyString === option.code);
if (option) {
return option.displayName;
}
// is key a name?
for(var i=0; i<options.length; i++){
if( keyString === options[i].displayName){
return key;
}
if (options.find(option => keyString === option.displayName)) {
return key;
}
// not a part of the option set
return null;
Expand Down

0 comments on commit 73245e0

Please sign in to comment.