You are viewing a single comment's thread. Return to all comments →
interface AdvancedArithmetic { divisorSum(n: number): number; } class Calculator implements AdvancedArithmetic { divisorSum(n: number): number { let sum = 0; for (let i = 1; i <= n; i++) { if (n % i === 0) { sum += i; } } return sum; } } function main() { let n: number = parseInt(readLine(), 10); const myCalculator: AdvancedArithmetic = new Calculator(); const sum = myCalculator.divisorSum(n); const interfaceName = "AdvancedArithmetic"; console.log("I implemented: " + interfaceName); console.log(sum); }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
TypeScript