Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38089
| From | "R.Wieser" <address@not.available> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Compare the Triplets | Printing two values. |
| Date | 2020-01-19 10:08 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <r016am$1p6l$1@gioia.aioe.org> (permalink) |
| References | <83a2fe4f-4564-4943-9515-b9bfc09b686a@googlegroups.com> |
manish,
> Can anybody suggest anything?
Most likely. :-)
> But somehow it displays a array with four elements with the values [1],
> [], [1], []
> for (let i = 0; i < 4; i ++) {
That counts from zero upto three, which is four elements. "Sample Input 0"
shows only three values for each player.
> points[i]=0;
You are not using it. What are you setting it ?
> points[i]=1;
> pointsArray.push(points[i])
Why the first line ? Why not simply push the value 1 ?
Also, you are *adding an element* with the result of the current
comparision, not (altering) the *total score* for each player.
> if (a[i] > b[i]) {
> points[i]=1;
> pointsArray.push(points[i])
....
> if (b[i] > a[i]) {
> points[i]=1;
> pointsArray.push(points[i])
Although the comparision is different for both, they both do the exact same
thing to the array. How do you/your program know for whom (Alice or Bob) it
is ?
> return pointsArray;
> }
> }
The above causes your function exits at the end of the first loop (with "i"
being zero), which also means that the result you posted has not been
generated by the posted code - the resulting array should either be empty or
contain a single element, the comparision result of the first scores by
Alice and Bob.
Bottom line, your program simply cannot return anything related to the
requested result. Both from not actually doing whats asked as well as
because errors in the code itself.
Biggest problem ? Using .push() . It /adds elements to the array/,
instead of incrementing a counter (stored in that array).
Just assume Alice and bob play ten rounds and alice has won them all. Your
resulting array would have ten elements with the value 1, instead of the
value 10 somewhere.
Hope that helps.
Regards,
Rudy Wieser
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Compare the Triplets | Printing two values. manish pamnani <manishpamnani169@gmail.com> - 2020-01-19 00:05 -0800
Re: Compare the Triplets | Printing two values. "R.Wieser" <address@not.available> - 2020-01-19 10:08 +0100
Re: Compare the Triplets | Printing two values. manish pamnani <manishpamnani169@gmail.com> - 2020-01-19 09:08 -0800
Re: Compare the Triplets | Printing two values. manish pamnani <manishpamnani169@gmail.com> - 2020-01-19 09:09 -0800
Re: Compare the Triplets | Printing two values. "R.Wieser" <address@not.available> - 2020-01-19 19:10 +0100
Re: Compare the Triplets | Printing two values. Julio Di Egidio <julio@diegidio.name> - 2020-01-19 09:42 -0800
Re: Compare the Triplets | Printing two values. "R.Wieser" <address@not.available> - 2020-01-19 10:47 +0100
Re: Compare the Triplets | Printing two values. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-19 13:03 -0800
Re: Compare the Triplets | Printing two values. Julio Di Egidio <julio@diegidio.name> - 2020-01-19 14:05 -0800
Re: Compare the Triplets | Printing two values. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-19 15:21 -0800
Re: Compare the Triplets | Printing two values. Julio Di Egidio <julio@diegidio.name> - 2020-01-19 15:39 -0800
csiph-web