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

97
Views
Splicing Stuff With Js

Ok, I'm making an evolution simulator and they need to get food to survive. Blah blah blah. But this splice isn't working and I don't know how to fix it

The code:

function track(blob, ob) {
    for (let i = 0; i < ob.length; i++) {
        const dist = Math.hypot(
            blob.x - ob[i].x, 
            blob.y - ob[i].y
        )

        if (dist - 20 - blob.size < 1) {
            blob.food++
            ob.splice(ob[i], 1)
        } else {
            const angle = Math.atan2(
                ob[i].x - blob.y,
                ob[i].y - blob.x
            )
            const velocity = {
                x: Math.cos(angle) / 2,
                y: Math.sin(angle) / 2
            }
            blob.velocity = velocity
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The way .splice() works is you specify the starting index, the number of items to delete, and a list of items to insert at that index.

var array = [3, 4, 5, 6];
array.splice(1, 1);
console.log(array); //[3, 5, 6]
array.splice(2, 0, 7);
console.log(array); //[3, 5, 7, 6]
array.splice(0, 2, 1, 8);
console.log(array); //[1, 8, 5, 7, 6]

Docs

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!