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

253
Views
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
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!