Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda