Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function amazingNumbers(n) {
- let num = n.toString().split('');
- let sum = 0;
- for (let i = 0; i < num.length; i++) {
- sum += Number(num[i]);
- }
- if (sum.toString().includes('9')) {
- console.log(`${n} Amazing? True`);
- } else {
- console.log(`${n} Amazing? False`);
- }
- }
- SOLUTION WITH SPREAD AND TERNARY OPERATORS:
- function amazingNumbers(n) {
- console.log(`${n} Amazing? ${[...n.toString()].map(Number).reduce((a, b) => a + b).toString().includes('9') ?'True' : 'False'}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement