Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38497 > unrolled thread

Map function works but has a "UNEXPECTED TOKEN" error how to fix it?

Started byJRough <janis.rough@gmail.com>
First post2020-07-11 18:26 -0700
Last post2020-07-12 11:17 -0700
Articles 8 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-11 18:26 -0700
    Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JJ <jj4public@vfemail.net> - 2020-07-12 10:40 +0700
      Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 10:46 -0700
        Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? James Kirk <noneya.invalid@gmail.com> - 2020-07-12 14:04 -0400
          Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 11:17 -0700
        Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 11:14 -0700
    Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? luserdroog <luser.droog@gmail.com> - 2020-07-11 22:41 -0700
      Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 11:17 -0700

#38497 — Map function works but has a "UNEXPECTED TOKEN" error how to fix it?

FromJRough <janis.rough@gmail.com>
Date2020-07-11 18:26 -0700
SubjectMap function works but has a "UNEXPECTED TOKEN" error how to fix it?
Message-ID<361f78f8-7ff6-4a2c-a3a6-6e4211cdc9d8o@googlegroups.com>
Map function works in playcode.io sandbox but it doesn't work in JS console.  Is that because playcode has babel?  In anycase, in playcode.io it says it has a bug but it still works.  How to fix the bug on the last line?  Error message is:error: unknown: Unexpected token, expected "," (8:28)


let users = [{name: 'John', gender: 'M'}, 
{name: 'David', gender: 'M'}, 
{name: 'Ashok', gender: 'M'}, 
{name: 'Naveen', gender: 'M'}, 
{name: 'Maddy', gender: 'F'}, 
{name: 'Mathilda', gender: 'F'}];
users.map((user ) => ({ user.gender ==="F" ? user:''})

thanks,

[toc] | [next] | [standalone]


#38498

FromJJ <jj4public@vfemail.net>
Date2020-07-12 10:40 +0700
Message-ID<vgruqw56pdxz$.r9nk01kx833s.dlg@40tude.net>
In reply to#38497
On Sat, 11 Jul 2020 18:26:39 -0700 (PDT), JRough wrote:
> Map function works in playcode.io sandbox but it doesn't work in JS
> console..  Is that because playcode has babel?  In anycase, in
> playcode.io it says it has a bug but it still works.  How to fix the bug
> on the last line?  Error message is:error: unknown: Unexpected token,
> expected "," (8:28)
> 
> let users = [{name: 'John', gender: 'M'}, 
> {name: 'David', gender: 'M'}, 
> {name: 'Ashok', gender: 'M'}, 
> {name: 'Naveen', gender: 'M'}, 
> {name: 'Maddy', gender: 'F'}, 
> {name: 'Mathilda', gender: 'F'}];
> users.map((user ) => ({ user.gender ==="F" ? user:''})
> 
> thanks,

Unwanted extra parenthesis. Read the code more closely.

[toc] | [prev] | [next] | [standalone]


#38503

FromJRough <janis.rough@gmail.com>
Date2020-07-12 10:46 -0700
Message-ID<fe581a0e-b2ec-492b-8035-3910ec7856b6o@googlegroups.com>
In reply to#38498
I took off parenthesis on last line but it still has error :  error unknown: Unexpected token, expected "," (9:0) starting on a new line after last line of code?  

let users = [{name: 'John', gender: 'M'}, 
{name: 'David', gender: 'M'}, 
{name: 'Ashok', gender: 'M'}, 
{name: 'Naveen', gender: 'M'}, 
{name: 'Maddy', gender: 'F'}, 
{name: 'Mathilda', gender: 'F'}];
users.map((user ) => ( user.gender ==="F" ? user: '')



error: unknown: Unexpected token, expected "," (9:0)

Saturday, July 11, 2020 at 8:40:32 PM UTC-7, JJ wrote:
> On Sat, 11 Jul 2020 18:26:39 -0700 (PDT), JRoughline  wrote:
> > Map function works in playcode.io sandbox but it doesn't work in JS
> > console..  Is that because playcode has babel?  In anycase, in
> > playcode.io it says it has a bug but it still works.  How to fix the bug
> > on the last line?  Error message is:error: unknown: Unexpected token,
> > expected "," (8:28)
> > 
> > let users = [{name: 'John', gender: 'M'}, 
> > {name: 'David', gender: 'M'}, 
> > {name: 'Ashok', gender: 'M'}, 
> > {name: 'Naveen', gender: 'M'}, 
> > {name: 'Maddy', gender: 'F'}, 
> > {name: 'Mathilda', gender: 'F'}];
> > users.map((user ) => ({ user.gender ==="F" ? user:''})
> > 
> > thanks,
> 
> Unwanted extra parenthesis. Read the code more closely.

[toc] | [prev] | [next] | [standalone]


#38504

FromJames Kirk <noneya.invalid@gmail.com>
Date2020-07-12 14:04 -0400
Message-ID<20200712140429.598876a6@james.kirk.invalid>
In reply to#38503
In Message: <fe581a0e-b2ec-492b-8035-3910ec7856b6o@googlegroups.com>
JRough <janis.rough@gmail.com> wrote:

> Saturday, July 11, 2020 at 8:40:32 PM UTC-7, JJ wrote:

>> On Sat, 11 Jul 2020 18:26:39 -0700 (PDT), JRoughline  wrote:  

[snip]

>>> users.map((user ) => ({ user.gender ==="F" ? user:''})
opening      ↑

>> Unwanted extra parenthesis. Read the code more closely. 

> I took off parenthesis on last line but it still has error :  error
> unknown: Unexpected token, expected "," (9:0) starting on a new line
> after last line of code?  

[snip]

> users.map((user ) => ( user.gender ==="F" ? user: '')
opening    ↑                                          no closing     ↑

users.map((user ) => ( user.gender ==="F" ? user: ''))

[snip]

mismatched/missing parentheses.

No closing parentheses for map.

-- 
James Kirk

[toc] | [prev] | [next] | [standalone]


#38507

FromJRough <janis.rough@gmail.com>
Date2020-07-12 11:17 -0700
Message-ID<b75fa671-d837-4686-a5f9-dd64b73d085do@googlegroups.com>
In reply to#38504
tnx,
On Sunday, July 12, 2020 at 11:04:37 AM UTC-7, James Kirk wrote:
> In Message: <fe581a0e-b2ec-492b-8035-3910ec7856b6o@googlegroups.com>
> JRough <janis.rough@gmail.com> wrote:
> 
> > Saturday, July 11, 2020 at 8:40:32 PM UTC-7, JJ wrote:
> 
> >> On Sat, 11 Jul 2020 18:26:39 -0700 (PDT), JRoughline  wrote:  
> 
> [snip]
> 
> >>> users.map((user ) => ({ user.gender ==="F" ? user:''})
> opening      ↑
> 
> >> Unwanted extra parenthesis. Read the code more closely. 
> 
> > I took off parenthesis on last line but it still has error :  error
> > unknown: Unexpected token, expected "," (9:0) starting on a new line
> > after last line of code?  
> 
> [snip]
> 
> > users.map((user ) => ( user.gender ==="F" ? user: '')
> opening    ↑                                          no closing     ↑
> 
> users.map((user ) => ( user.gender ==="F" ? user: ''))
> 
> [snip]
> 
> mismatched/missing parentheses.
> 
> No closing parentheses for map.
> 
> -- 
> James Kirk

[toc] | [prev] | [next] | [standalone]


#38505

FromJRough <janis.rough@gmail.com>
Date2020-07-12 11:14 -0700
Message-ID<e31840fd-ae98-4594-8acf-01238161d4bdo@googlegroups.com>
In reply to#38503
On Sunday, July 12, 2020 at 10:46:39 AM UTC-7, JRough wrote:
> I took off parenthesis on last line but it still has error :  error unknown: Unexpected token, expected "," (9:0) starting on a new line after last line of code?  
> 
> let users = [{name: 'John', gender: 'M'}, 
> {name: 'David', gender: 'M'}, 
> {name: 'Ashok', gender: 'M'}, 
> {name: 'Naveen', gender: 'M'}, 
> {name: 'Maddy', gender: 'F'}, 
> {name: 'Mathilda', gender: 'F'}];
> users.map((user ) => ( user.gender ==="F" ? user: '')
> 
> 
> 
> error: unknown: Unexpected token, expected "," (9:0)
> 
> Saturday, July 11, 2020 at 8:40:32 PM UTC-7, JJ wrote:
> > On Sat, 11 Jul 2020 18:26:39 -0700 (PDT), JRoughline  wrote:
> > > Map function works in playcode.io sandbox but it doesn't work in JS
> > > console..  Is that because playcode has babel?  In anycase, in
> > > playcode.io it says it has a bug but it still works.  How to fix the bug
> > > on the last line?  Error message is:error: unknown: Unexpected token,
> > > expected "," (8:28)
> > > 
> > > let users = [{name: 'John', gender: 'M'}, 
> > > {name: 'David', gender: 'M'}, 
> > > {name: 'Ashok', gender: 'M'}, 
> > > {name: 'Naveen', gender: 'M'}, 
> > > {name: 'Maddy', gender: 'F'}, 
> > > {name: 'Mathilda', gender: 'F'}];
> > > users.map((user ) => ({ user.gender ==="F" ? user:''})
> > > 
> > > thanks,
> > 
> > Unwanted extra parenthesis. Read the code more closely.

don't think you are supposed to use a map for this function but it works anyway as a side effect

[toc] | [prev] | [next] | [standalone]


#38500

Fromluserdroog <luser.droog@gmail.com>
Date2020-07-11 22:41 -0700
Message-ID<46ffdb1c-eaac-41a8-8b91-facd2f3c0051o@googlegroups.com>
In reply to#38497
On Saturday, July 11, 2020 at 8:26:44 PM UTC-5, JRough wrote:
> Map function works in playcode.io sandbox but it doesn't work in JS console.  Is that because playcode has babel?  In anycase, in playcode.io it says it has a bug but it still works.  How to fix the bug on the last line?  Error message is:error: unknown: Unexpected token, expected "," (8:28)
> 
> 
> let users = [{name: 'John', gender: 'M'}, 
> {name: 'David', gender: 'M'}, 
> {name: 'Ashok', gender: 'M'}, 
> {name: 'Naveen', gender: 'M'}, 
> {name: 'Maddy', gender: 'F'}, 
> {name: 'Mathilda', gender: 'F'}];
> users.map((user ) => ({ user.gender ==="F" ? user:''})
> 
> thanks,

JJ has addressed your syntax, but have you considered 'filter' instead 
of 'map'? It's hard to imagine what those empty strings do for you.

[toc] | [prev] | [next] | [standalone]


#38506

FromJRough <janis.rough@gmail.com>
Date2020-07-12 11:17 -0700
Message-ID<45173d69-1a2e-4c4c-9b81-bd722238657bo@googlegroups.com>
In reply to#38500
On Saturday, July 11, 2020 at 10:41:54 PM UTC-7, luserdroog wrote:
> On Saturday, July 11, 2020 at 8:26:44 PM UTC-5, JRough wrote:
> > Map function works in playcode.io sandbox but it doesn't work in JS console.  Is that because playcode has babel?  In anycase, in playcode.io it says it has a bug but it still works.  How to fix the bug on the last line?  Error message is:error: unknown: Unexpected token, expected "," (8:28)
> > 
> > 
> > let users = [{name: 'John', gender: 'M'}, 
> > {name: 'David', gender: 'M'}, 
> > {name: 'Ashok', gender: 'M'}, 
> > {name: 'Naveen', gender: 'M'}, 
> > {name: 'Maddy', gender: 'F'}, 
> > {name: 'Mathilda', gender: 'F'}];
> > users.map((user ) => ({ user.gender ==="F" ? user:''})
> > 
> > thanks,
> 
> JJ has addressed your syntax, but have you considered 'filter' instead 
> of 'map'? It's hard to imagine what those empty strings do for you.

thx

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web