Skip to content

Listing4-2.js doesn't work #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Ambiorix9 opened this issue Sep 9, 2019 · 5 comments
Closed

Listing4-2.js doesn't work #1

Ambiorix9 opened this issue Sep 9, 2019 · 5 comments

Comments

@Ambiorix9
Copy link

Ambiorix9 commented Sep 9, 2019

The following line:

if (fieldName.trim().length > 0) {

has this error:

TypeError: fieldName.trim is not a function

@Ambiorix9
Copy link
Author

The code works OK if you iterate over headers[0] rather than headers:

headers[0].forEach((fieldName, columnIndex) => { if (fieldName.trim().length > 0) { record[fieldName] = row[columnIndex]; } });

@ashleydavis
Copy link
Member

ashleydavis commented Sep 9, 2019

Thanks for your feedback.

I've just tried the code direct from GitHub and it works ok for me.

Here is what I did:

git clone https://github.com/Data-Wrangling-with-JavaScript/Chapter-4.git
cd Chapter-4
npm install
node listing-4.2.js

Output:

> node listing-4.2.js
[ { Mag: '9.5',
    Location: ' Bio-Bio, Chile',
    'Alternative Name': 'Valdivia Earthquake',
    'Date (UTC)': '1960-05-22',
    'Time (UTC)': '19:11',
    Latitude: '38.14°S',
    Longitude: '73.41°W',
    References: 'Kanamori & Anderson, 1975' },
  { Mag: '9.2',
    Location: ' Southern Alaska',
    'Alternative Name':
     '1964 Great Alaska Earthquake, Prince William Sound Earthquake, Good Friday Earthquake',
    'Date (UTC)': '1964-03-28',
    'Time (UTC)': '03:36',
    Latitude: '60.91°N',
    Longitude: '147.34°W',
    References: 'Kanamori & Anderson, 1975' },
  { Mag: '9.1',
    Location: ' Off the West Coast of Northern Sumatra',
    'Alternative Name':
     'Sumatra-Andaman Islands Earthquake, 2004 Sumatra Earthquake and Tsunami, Indian Ocean Earthquake',
    'Date (UTC)': '2004-12-26',
    'Time (UTC)': '00:58',
    Latitude: '3.30°N',
    Longitude: '95.98°E',
    References: 'Duputel et al., 2012' },
  { Mag: '9.1',
    Location: ' Near the East Coast of Honshu, Japan',
    'Alternative Name': 'Tohoku Earthquake',
    'Date (UTC)': '2011-03-11',
    'Time (UTC)': '05:46',
    Latitude: '38.30°N',
    Longitude: '142.37°E',
    References: 'Duputel et al., 2012' },
...

Is this how you run the code?

Maybe you have a different version of Node.js?

I have version 10.15.2.

Also, which operating system are you running on?

Please open a terminal and run node --version and tell me which version you are using. If you can tell me that I'll be able to try the code with that version as well.

@Ambiorix9
Copy link
Author

Ambiorix9 commented Sep 9, 2019 via email

@ashleydavis
Copy link
Member

Ok thanks for letting me know.

Hopefully at some point we'll get the book updated.

For the moment please use GitHub for the latest code examples!

If you spot other problems please report them here.

@ashleydavis
Copy link
Member

Also if you haven't already, please follow me on Twitter for updates on my new book: https://twitter.com/ashleydavis75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants