Hi Sinan,
Thank you for the links and your suggestions. However, I did not quite
understand your suggestions and I tried this map function which did not
work:
function(doc) {
var judge = function (no1, no2) {
var unexpect = "X";
var letter1 = unexpect, letter2 = unexpect;
for (var i in this.chr) {
var chr = this.chr[i];
if (chr.no == no1) {
letter1 = chr.letter;
} else if (chr.no == no2) {
letter2 = chr.letter;
}
}
if (letter1 != letter2 && letter1 != unexpect && letter2 !=
unexpect) {
return true;
}
return false;
};
emit(judge(n1, n2), doc);
}
Could you please explain your ideas a little more?
Thank you in advance.
Mic
On Wed, Dec 31, 2014 at 10:57 PM, Sinan Gabel <[email protected]> wrote:
> Hi!
>
> You may want to take a look at the basics here:
> http://docs.couchdb.org/en/latest/couchapp/views/index.html and Cloudant
> has some interactive samples at:
> https://cloudant.com/for-developers/all_docs/
>
> *Using map*: You may want to emit the letters and use keys to find the
> docs.
>
> *Not using map*: Name each doc something "smart", and use keys to find the
> docs.
>
> Br,
> Sinan
>
> On 31 December 2014 at 13:05, Mic <[email protected]> wrote:
>
> > Hi,
> > I tried to create a map function which should use the following
> conditions:
> >
> > - e.g. chr.no = 5 and chr.no = 6
> > - chr.letter between two objects/dicts in chr are not the same and no X
> >
> > I have the following function but I do not know how to combine it with
> > `emit`
> >
> > var judge = function (no1, no2) {
> > var unexpect = "X";
> > var letter1 = unexpect, letter2 = unexpect;
> > for (var i in this.chr) {
> > var chr = this.chr[i];
> > if (chr.no == no1) {
> > letter1 = chr.letter;
> > } else if (chr.no == no2) {
> > letter2 = chr.letter;
> > }
> > }
> > if (letter1 != letter2 && letter1 != unexpect && letter2 !=
> > unexpect) {
> > return true;
> > }
> > return false;
> > };
> >
> >
> > CouchDB has the below content:
> >
> >
> > {
> > "total_rows":5,
> > "offset":0,
> > "rows":[
> > {
> > "_id":"10",
> > "_rev":"3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
> > "chr":[
> > {
> > "letter":"T",
> > "no":4
> > },
> > {
> > "letter":"A",
> > "no":5
> > },
> > {
> > "letter":"X",
> > "no":6
> > }
> > ]
> > },
> > {
> > "_id":"14",
> > "_rev":"3-21300d06c31224416b8ff71b71b304d8",
> > "chr":[
> > {
> > "letter":"T",
> > "no":4
> > },
> > {
> > "letter":"G",
> > "no":5
> > },
> > {
> > "letter":"G",
> > "no":6
> > }
> > ]
> > },
> > {
> > "_id":"7",
> > "_rev":"2-1516ba547bdd21724158bc854f39f66b",
> > "chr":[
> > {
> > "letter":"C",
> > "no":5
> > },
> > {
> > "letter":"T",
> > "no":6
> > }
> > ]
> > },
> > {
> > "_id":"8",
> > "_rev":"2-750078ccc9e74616f33a2537e41b8414",
> > "chr":[
> > {
> > "letter":"C",
> > "no":5
> > },
> > {
> > "letter":"T",
> > "no":6
> > }
> > ]
> > },
> > {
> > "_id":"9",
> > "_rev":"2-3d68352a2d98c56fd322ae674fb7c38a",
> > "chr":[
> > {
> > "letter":"A",
> > "no":5
> > },
> > {
> > "letter":"G",
> > "no":6
> > }
> > ]
> > }
> > ]
> > }
> >
> > How is it possible to write a map function combine with the above `judge`
> > function or maybe there is better way to do it?
> >
> > P.S. I also asked the same question here (
> >
> >
> http://stackoverflow.com/questions/27688196/map-function-with-a-helper-function-in-couchdb
> > )
> >
> > Thank you in advance.
> >
> > Mic
> >
>