Untitled

 avatar
unknown
javascript
3 months ago
514 B
3
Indexable
function enBuyukFor(dizi) {
  let enBuyuk = dizi[0];
  for (let i = 1; i < dizi.length; i++) {
    if (dizi[i] > enBuyuk) {
      enBuyuk = dizi[i];
    }
  }
  return enBuyuk;
}

function enBuyukReduce(dizi) {
  return dizi.reduce((enBuyuk, sayi) => {
    return sayi > enBuyuk ? sayi : enBuyuk;
  });
}

const sayilar = [1000, 6000, 87000, 450000, 990, 3];

console.log("For ile en büyük sayı: " + enBuyukFor(sayilar));
console.log("Reduce ile en büyük sayı: " + enBuyukReduce(sayilar));
Editor is loading...
Leave a Comment