0

I could not find anything online, but I'm curious if there's a more concise syntax for the following example:

if ( obj[a][b][c] != 0 ) {
    obj[a][b][c] = ( obj[a][b][c] / 2 ) + obj[a][b][c] + 100;
    obj[x][y][z] = obj[a][b][c];
}

I know for the times that I'm working with the actual value I could just cache it in a temporary variable, but I'm more interested in replacing the "obj[...] = " part with something more concise.

1
  • obj[a][b][c]=obj[x][y][z]=(a=>a?a/2+a+100:a)(obj[a][b][c]); Commented Jun 22, 2017 at 10:31

1 Answer 1

3

Well you could extract a variable and as @Jonas W noted in the comments you can combine assigments:

var cellP = obj[a][b];
var cell = cellP[c];
if ( cell != 0 ) {
    obj[x][y][z] = cellP[c] = 1.5 * cell + 100;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.