Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
"Cannot read property of undefined."

I have some simple code that I've written in Python. It's working. Now I'm trying to port it to JavaScript. The code is here. I'm getting this error:

sketch.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'compression_ratio')
    at w (sketch.js:7:39)
    at ifsp (sketch.js:37:13)
    at draw (sketch.js:54:14)
    at p5._main.default.redraw (p5.js:71990:27)
    at _draw (p5.js:64140:25)

What's going wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The error is here (Starting line 28).

if (prob_sum > r) {
  attractor_index = j - 1;
} else {
  attractor_index = j;
}

If r is smaller than 1/3 (probability value that you have defined in line 51) you will decrement attractors_index using j - 1 and if that happens in the first iteration attractors_index will be -1 as j = 0. In that case attractors[attractors_index] will return undefined and you call w() with undefined instead of the object you expect, hence attractors.compression_ratio will not have a property compression_ratio and the error is thrown.

You can check/ reproduce that easily by manually setting r to > or < 1/3.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!