4
\$\begingroup\$

I have some code that reads from an XML file and updates if needed. I want to move some of the stuff around. Here is the code overall:

 priv.refAddUpdate = function(addressDoc, addressLine, value)
{
  if(!S(value).isEmpty())
  {
     var found = $(addressDoc).find('addressLines').find(addressLine);

     if(found.length > 0)
     {
        found.text(value);
     }
     else
     {
        $(addressDoc).find('addressLines').append('<addressLine>' + value + '</addressLine>');
     }
  }
  else
  {
     $(addressDoc).find(addressLine).remove();
  }
   };
   priv.updateAddress = function(addressDoc, address)
   {
  if(addressDoc)
  {
     priv.addUpdate(addressDoc, 'firstName', address.firstName);
     priv.addUpdate(addressDoc, 'middleName', address.middleName);
     priv.addUpdate(addressDoc, 'lastName', address.lastName);
     priv.addUpdate(addressDoc, 'companyName', address.companyName);
     priv.refAddUpdate(addressDoc, ':nth-child(1)', address.address);
     priv.refAddUpdate(addressDoc, ':nth-child(2)', address.ref1);
     priv.refAddUpdate(addressDoc, ':nth-child(3)', address.ref2);
     priv.addUpdate(addressDoc, 'city', address.city);
     priv.addUpdate(addressDoc, 'state', address.state);
     priv.addUpdate(addressDoc, 'zip', address.zip);
     $(addressDoc).find('countryCode').text(address.country);
     $(addressDoc).find('shipMethod').text(address.shipMethod);
     priv.addUpdate(addressDoc, 'phoneOne', address.phoneOne);
     priv.addUpdate(addressDoc, 'phoneTwo', address.phoneTwo);
     priv.addUpdate(addressDoc, 'email', address.email);
     }
  };

the big thing is I want to move the :nth-child(1)||:nth-child(2)||:nth-child(3) up into this so that way I can just call perhaps a 1 2 or 3 based on the child instead of how it is now.

priv.refAddUpdate = function(addressDoc, addressLine, value)
    {
  if(!S(value).isEmpty())
  {
     var found = $(addressDoc).find('addressLines').find(addressLine);

     if(found.length > 0)
     {
        found.text(value);
     }
     else
     {
        $(addressDoc).find('addressLines').append('<addressLine>' + value + '</addressLine>');
     }
  }
  else
  {
     $(addressDoc).find(addressLine).remove();
  }
  };

Perhaps it would look like this:

 priv.refAddUpdate(addressDoc, '(1)', address.address);

Or something close to that. Any advice would be awesome!

\$\endgroup\$

closed as off-topic by Sᴀᴍ Onᴇᴌᴀ, Mast, Toby Speight, IEatBagels, Dannnno Oct 15 at 13:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Sᴀᴍ Onᴇᴌᴀ, IEatBagels, Dannnno
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Anything guys?, \$\endgroup\$ – Norcal Jun 13 '16 at 5:06
  • 1
    \$\begingroup\$ where does priv come from? please [edit[ your post to explain this \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Oct 12 at 5:29

Browse other questions tagged or ask your own question.