function createArithmetic(from)
{
if (!Number.isInteger(from)) {
throw new Error('Invalid from argument');
}
return function(to) {
if (!Number.isInteger(to)) {
throw new Error('Invalid to argument');
}
return (from + to) / 2 * (Math.abs(from - to) + 1);
}
}
const getArithmeticProgressionSumOne = createArithmetic(1);
alert(getArithmeticProgressionSumOne(2) === 3);//1 + 2
alert(getArithmeticProgressionSumOne(8) === 36);//1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
const getArithmeticProgressionSumFive = createArithmetic(5);
alert(getArithmeticProgressionSumFive(8) === 26);// 5 + 6 + 7 + 8
alert(getArithmeticProgressionSumFive(4) === 9);// 4 + 5