I have this ternary operator
function digPow(n, p){
return Number.isInteger((""+n).split("").map((num,index) => Math.pow(parseInt(num),(p+index))).reduce((a, b) => a + b, 0)/n) ? (""+n).split("").map((num,index) => Math.pow(parseInt(num),(p+index))).reduce((a, b) => a + b, 0)/n : -1;
}
As you can see this is a very long 1 liner. My question is, how do I recall the value inside the Number.isInteger() so that I don't have to repeat it again for the ternary operator in only 1 line.
This is the code I need a value from:-
(""+n).split("").map((num,index) => Math.pow(parseInt(num),(p+index)))
.reduce((a, b) => a + b, 0)/n
Is there any syntax for this? I am relatively new to JS
EDIT: The main question is actually: "Is it possible to call the value from inside a ternary operator without using a variable"
EDIT-2: Sorry for my bad coding. Here is a simpler way to ask my question
const x = 6
const y = 3
console.log(Number.isInteger(x+y/3) ? x+y/3 : -1)
Is it possible to recall the x+y/3 value without repeating it or making a new variable?