Final Value of Variable After Performing Operations
EasyArrayStringSimulation
Solution
export function finalValueAfterOperations(operations: string[]): number {
function operate(x: number, operation: string) {
if (operation === '--X' || operation === 'X--') {
return x - 1;
}
return x + 1;
}
return operations.reduce(operate, 0);
}