0

Okay, this is quite related to my previous quesion, but still (so you don't have to travel to that page..)

I have a string in the format

ItemName1:Rate1:Tax1_ItemName2:Rate2:Tax2:_ItemName3:Rate3:Tax3_ItemName4:Rate4:Tax4

the user will pass 4 args, first will tell which element to take, when this list is split by _, and other 3 will tell the new values of items.
For example, if user passes 2, Denim Jeans, 399.00, 14.34. The original string would become

ItemName1:Rate1:Tax1_ItemName2:Rate2:Tax2:_Denim Jeans:399.00:14.34_ItemName4:Rate4:Tax4

First split at _, get the element at index 2 (the value user supplied), and then split that element at : and then replace those items with the value supplied.

I got around a lot, here is the jsfiddle for that. But I am just stuck at the last part that will do the appropriate concatenation.
Can help please help me make this last function?

Edit : updated the fiddle!

7
  • What's the purpose of the first $.map() call in your function? Commented Sep 15, 2012 at 5:45
  • With the answer I posted in the other question you get a proper array of items from a string with that format, if you want to change something in that array you can do it by index. I don't quite get what' you're trying to do though. Can't you just use an object instead? Commented Sep 15, 2012 at 5:49
  • @nnnnnn: after the list is split by _, map returns the elements of that element when split by :, which is then concatenated to make the string that will be replace. Commented Sep 15, 2012 at 5:51
  • @elclanrs: I tried using an object, but couldn't event get to this part of forming string that will be replaced. If you want, I can post a detailed explanation of the scenario and what I am exactly trying to do. Commented Sep 15, 2012 at 5:52
  • Wouldn't _itemsToReplace = ary[index].split(deli2); do the same thing as that first $.map()? (If the callback you pass to $.map() just returns the first parameter unchanged all you're doing is making a shallow copy of the array.) Commented Sep 15, 2012 at 5:53

1 Answer 1

1

couple of things here...

Not sure why you are taking list as a string. it would have been better you have used a json object.

and in your example you are getting the 2nd string in the required format..so it doesn't make sense to split it and join again.. you just need to replace the array item with the argList

here is the modified jsfidle. hope i understood your problem right. tell me if there are any gaps... http://jsfiddle.net/k87Zw/5/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man! that did the trick! +1 and thanks for making it clear, I was really confused!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.