Answer:
let a = [4, 0, 1, -2, 3];
let b = a.map( (e, i, arr) => (arr[i-1] || 0)+arr[i]+(arr[i+1] || 0) );
console.log(b);
Step-by-step explanation:
The map operator is excellent for this. The || 0 operator prevents the undefined out of bounds value from ruining the result.
BTW this solution is in javascript. Other languages will presumably require more code.