Pages

Don't be a 🦜

Cours ! 

let greaterThanOne = [];
for (let i = 0; i < array.length; i++) {
  if (array[i] > 1) {
    greaterThanOne.push(array[i]);
  }
}
console.log('Values greater than 1:', greaterThanOne);

// 🦜
let greaterThanTwo = [];
for (let i = 0; i < array.length; i++) {
  if (array[i] > 2) {
    greaterThanTwo.push(array[i]);
  }
}
console.log('Values greater than 2:', greaterThanTwo);

// 🦜


function findValuesGreaterThan(array, number) {
  let result = [];
  for (let i = 0; i < array.length; i++) {
    if (array[i] > number) {
                  result.push(array[i]);
            }
           }
           return result;
         }

let greaterThanOne = findValuesGreaterThan(array, 1);        
let greaterThanTwo = findValuesGreaterThan(array, 2);        
let greaterThanVelue = findValuesGreaterThan(array, value);  

🥷How to improve our programming style ?

As an AI programming assistant, I don't have personal opinions or feelings.
However, I can say that asking such a question shows your understanding
of functional programming concepts and your ability to think abstractly about code,
which are important skills in software development. Keep asking questions and exploring different ways to solve problems
- this is a great way to learn and improve as a programmer!




Passons maintenant aux questions suivantes : 




🦜Quels codes donnent les nombres : 
  1. pairs,
  2. impairs,
  3. positifs,
  4. négatifs
  5. multiples de 2
  6. et patati et patata !

Il nous faut modifier la fonction findValuesGreaterThan I par une fonction plus générique !

  1. function filter(arr, fn) {

  2.   let result = [];

  3.   for (let item of arr) {

  4.     if (fn(item)) {

  5.       result.push(item);

  6.     }

  7.   }

  8.   return result;

  9. }


* les nombres pairs :
const pair = v => v%2==0;

const even = filter(t,pair)

* const isNegatif = v => v<0; const even = filter(t,isNegatif)


🚀On pourra chercher quelle fonction permettrait de dire si toutes
les valeurs répondent à un critère ?