Advertisement
barbos01

tema2

May 9th, 2022
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.log("Ex1");
  2. const verificare1 = numar => {
  3.     if (numar % 2 == 1) {
  4.         return numar * numar;
  5.     } else return numar - 2;
  6. }
  7. console.log(verificare1(10));
  8. console.log(verificare1(9));
  9. console.log("--------------------")
  10.  
  11.  
  12. console.log("Ex2");
  13. function isPrim(number) {
  14.     if (number <= 1) {
  15.         return false;
  16.     } else {
  17.         for (let i = 2; i < number; i++) {
  18.             if (number % i == 0) {
  19.                 return false;
  20.             }
  21.         }
  22.         return true;
  23.     }
  24. }
  25.  
  26. function arrayPrim(vector) {
  27.     const array = [];
  28.     for (let i = 0; i < vector.length; i++) {
  29.         if (isPrim(vector[i])) {
  30.             array.push(vector[i]);
  31.         }
  32.     }
  33.     return array;
  34. }
  35.  
  36. const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  37. const primArr = arrayPrim(arr);
  38. console.log(primArr);
  39. console.log("--------------------")
  40.  
  41.  
  42. console.log("Ex3");
  43. let strOnly = [];
  44. const str = [1, "1", "salut", 2, 6, true, "true"];
  45. str.forEach(myFunction);
  46.  
  47. function myFunction(item) {
  48.     if (typeof item === "string") {
  49.         strOnly.push(item);
  50.     }
  51. }
  52. console.log(strOnly);
  53. console.log("--------------------")
  54.  
  55.  
  56. console.log("Ex4");
  57. function addDigits(str) {
  58.     let sumOdd = 0;
  59.     for (let index = 0; index < str.length; index++) {
  60.         if (isNaN(str[index])) {
  61.             continue;
  62.         }
  63.         sumOdd += Number(str[index]) % 2 != 0 ? Number(str[index]) : 0;
  64.     }
  65.     console.log(sumOdd);
  66. }
  67. addDigits("152Cab2cf3");
  68. console.log("--------------------")
  69.  
  70.  
  71. console.log("Ex5");
  72. const notaExamen = 11;
  73. switch (notaExamen) {
  74.     case 1:
  75.     case 2:
  76.     case 3:
  77.     case 4:
  78.         console.log("Picat");
  79.         break;
  80.     case 5:
  81.         console.log("Ati trecut, cu indulgenta..");
  82.         break;
  83.     case 6:
  84.     case 7:
  85.         console.log("Ati trecut.")
  86.         break;
  87.     case 8:
  88.     case 9:
  89.     case 10:
  90.         console.log("Ati trecut cu brio!")
  91.     default:
  92.         console.log("Nota invalida!")
  93.         break;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement