Pages

IA : Github copilot

🆘Aide Ă  l'Ă©criture de code 

Tapez 
function findLowerValue(tab, callback) {

🚀Copilot comprend et vous propose le code !



đŸ„‡Mieux encore, copilot  propose des tests ! 

đŸ„‡Code gĂ©nĂ©rĂ© par copilot ! 
const tab = [4, 6, 1, 3, 2, 5];
const lowerValue = findLowerValue(tab, (value) => value);
console.log(lowerValue); // 1

const lowerValue2 = findLowerValue(tab, (value) => -value);
console.log(lowerValue2); // 6

Voici un code gĂ©nĂ©rĂ© Ă©tape par Ă©tape par copilot ! 
C'est le pilot qui doit guider le copilot.

function calculator(str){
  // regexp to match the numbers and operators
  const regexp = /(\d+)(\+|\-|\*|\/)(\d+)/;
  //use match method to get the numbers and operators
  const match = str.match(regexp);
  //use parseInt to convert the string to number
  const num1 = parseInt(match[1]);
  const num2 = parseInt(match[3]);

  //use switch to do the calculation
  switch(match[2]){
    case '+':
      return num1 + num2;
    case '-':
      return num1 - num2;
    case '*':
      return num1 * num2;
    case '/':
      if(num2 === 0){
        return 'Cannot divide by 0';
      }
      return num1 / num2;
  }
}

// given test cases
console.log(calculator('1+1')); // 2

đŸ„‡Pythontutor