Untitled
Anonymous
Plain Text
10/02/2025 4:36 PM
738 B
13
Indexable
Never
const sayilar = [14, 53, 12, 4, 9, 1, 4];
function forDongusu(dizi) {
if (!dizi || dizi.length === 0) {
return undefined;
}
let enBuyuk = dizi[0];
for (let i = 1; i < dizi.length; i++) {
if (dizi[i] > enBuyuk) {
enBuyuk = dizi[i];
}
}
return enBuyuk;
}
function reduce(dizi) {
if (!dizi || dizi.length === 0) {
return undefined;
}
const sonuc = dizi.reduce((enBuyuk, mevcutSayi) => {
return mevcutSayi > enBuyuk ? mevcutSayi : enBuyuk;
});
return sonuc;
}
const sonucFor = forDongusu(sayilar);
const sonucReduce = reduce(sayilar);
console.log(`For yontemine gore sonuc: ${sonucFor}`);
console.log(`Reduce metodu yontemine gore sonuc: ${sonucReduce}`);Editor is loading...
Leave a Comment