Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var sam = [1, 2, 3, 4, 7, 3, 2, 5];
  2. var sedia = [1, 2, 3];
  3. var saluti = ['ciao', 'buongiorno', 'buonasera'];
  4.  
  5. //console.log(sam.indexOf(100));
  6.  
  7. // console.log(saluti.indexOf('ciao'));
  8.  
  9. function isPari(elem){
  10.   if (elem % 2 == 0){
  11.     return true;
  12.   }
  13.   return false;
  14. }
  15.  
  16. function test(elem){
  17.   return (elem % 5 == 0 || elem == 7);
  18. }
  19.  
  20.  
  21.  
  22.  
  23. function sommaPari(acc, val) {
  24.   if (val % 2 == 0){
  25.     return acc + val;
  26.   } else {
  27.     return acc;
  28.   }
  29. }
  30.  
  31.  
  32.  
  33. function sum(acc, val){
  34.   return acc + val;
  35. }
  36.  
  37. console.log('somma=' + sedia.reduce(sum, 0));
  38.  
  39.  
  40. function stampa(numero, indice) {
  41.   console.log("elemento " + numero + " in posizione " + indice);
  42. }
  43.  
  44. function stampaSePari(val) {
  45.   if (val % 2 == 0) {
  46.     console.log(val);
  47.   }
  48. }
  49.  
  50. function meno100(val) {
  51.   console.log(val-100);
  52. }
  53.  
  54. // sam.forEach(stampaSePari);
  55. // sam.forEach(meno100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement