Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printAndSum(startNum, endNum) {
- let output = '';
- let sum = 0;
- for (let i = startNum; i <= endNum; i++) {
- output += i + ' ';
- sum += i;
- }
- console.log(output);
- console.log(`Sum: ${sum}`);
- }
- Адванс решение:
- function printAndSum(startNum, endNum) {
- let array = Array(endNum - startNum + 1).fill().map((_, i) => startNum + i);
- console.log(`${array.join(' ')}\nSum: ${array.reduce((a,b) => a+b)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement