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

252
Vistas
Is there a way to reference the left side of an expression from within the right side of an expression / can it be implemented into a language?

A while ago I stumbled upon this snippet of code in the MDN web docs:

function Date(n) {
    return ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][n%7 || 0];
}

I found it interesting as I've never seen array syntax used like that before. Sure I've created arrays on the fly and done something like [1, 2, 3][0], but in this case with the [n%7 || 0], it uses n for the index we want and a most importantly that hardcoded 7 for the array length in order to "wrap" the n to the array.

Today I came across this question and when coding my answer:

let sampletext="Home/Student/Hello.txt"

let textarr = sampletext.split('/');
let idarray = textarr.map((x, i) => {
  if(i === 0)
    return { id: x, parent: '' };
  
  return { id: x, parent: textarr[i - 1] };
});

console.log(idarray);

I noticed that I had to do the .split separately, as otherwise I couldn't meaningfully refer to the arr[i - 1] since if I had sampletext.split('/').map(...), I didn't have a reference to the array which sampletext.split('/') makes.

These two examples have something in common, which I'd like to call "missing left referencing" and what I mean by that is something like this:

Example 1 with "left referencing"

function Date(n) {
    return ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][n%left.length || 0];
}

Êxample 2 with "left referencing"

//  "mapLeft" magically pulls whatever .split('/') spits out by using "left" keyword internally and passes it to the function passed to the mapLeft
let idarray = sampletext.split('/').mapLeft((x, i, left) => {
  if(i === 0)
    return { id: x, parent: '' };

  return { id: x, parent: left[i - 1] };
});

So what I am looking for is a way to basically get a reference to the left side of an expression, from within the right side of an expression, the idea being that left would be a reserved word similar to this.

I don't think that anything like this exists in JavaScript at least, but I am wondering if any language supports such syntax and if syntax like this is even possible to implement into a language?

about 4 years ago · Juan Pablo Isaza
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