# how to read complex cookie data - jquery cookie

I have got to read and manipulate a cookie that looks like this:

cookiename = 9918430821007~12.00 | 7C9918430831006~3.00 | 7C7501031311309~50.30

The above cookie has 3 values, each separated by "|" Each value is separated by a "~"

The first item(9918430821007) represents a unique product id The second (12.00) represents the amount in usd

I am stuck in the following:

How do i check if the product ID exist when adding a product to a shopping cart(to prevent duplicate entries)?

I have got to make a total $ of all usd values, how to make the total of all these amout pairs (12.00,3.00,50.30..etc)

FYI i am using jquery 1.72 + jquery.cookie.js

Any help would much be appreciated

Thanks

## Answers

How about something like this ?

var Products = $.cookie('cookiename').split(' | ') // Products= ['9918430821007~12.00', '7C9918430831006~3.00', '7C7501031311309~50.30']

You could then do this:

Products[0].split('~')[0] // 9918430821007 Products[0].split('~')[1] // 12.00

...or something of that sort. Hope this helps!

**Edit** Here's a jsFiddle to help

### Need Your Help

### Algorithm to traverse a grid collecting as many points as possible

algorithm math graph-algorithm discrete-mathematics dna-sequence

Consider a 2-dimensional m*n grid where each cell can contain either a 1 or a 0. Find the greatest value a traversal can acquire by moving through this grid. The value can be increased by traversing