/** * @param {number[]}arr * @return {number} */ var sumOddLengthSubarrays = function (arr) { let length = 1; let res = 0; while (length <= arr.length) { let i = 0; while (i <= arr.length - length) { res += arr.slice(i, i + length).reduce((a, b) => +a + +b); i++; } length += 2; } return res; };