Advertisement
Spocoman

04.Amazing Numbers

Jan 16th, 2022 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function amazingNumbers(n) {
  2.     let num = n.toString().split('');
  3.     let sum = 0;
  4.  
  5.     for (let i = 0; i < num.length; i++) {
  6.         sum += Number(num[i]);
  7.     }
  8.  
  9.     if (sum.toString().includes('9')) {
  10.         console.log(`${n} Amazing? True`);
  11.     } else {
  12.         console.log(`${n} Amazing? False`);
  13.     }
  14. }
  15.  
  16. SOLUTION WITH SPREAD AND TERNARY OPERATORS:
  17.  
  18. function amazingNumbers(n) {
  19.     console.log(`${n} Amazing? ${[...n.toString()].map(Number).reduce((a, b) => a + b).toString().includes('9') ?'True' : 'False'}`);
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement