Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
77 changes: 67 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* nesneyiTrimle({ isim: ' jane ' }) // yeni bir nesne döndürür { name: 'jane' }
*/
function nesneyiTrimle(obj) {
// {name: 'Dogancan', surname: 'Kinik'}
// ✨ kodlar buraya
Object.keys(obj).forEach(element => obj[element] = obj[element].trim());
return obj
}

/**
Expand All @@ -20,6 +23,8 @@ function nesneyiTrimle(obj) {
*/
function verileniTrimle(obj, prop) {
// ✨ kodlar buraya
obj[prop] = obj[prop].trim()
return obj
}

/**
Expand All @@ -32,16 +37,25 @@ function verileniTrimle(obj, prop) {
*/
function enBuyukTamsayiyiBul(tamsayilar) {
// ✨ kodlar buraya
let max = 0
tamsayilar.forEach(element => {
if (element.tamsayi > max) {
max = element.tamsayi
}
})
return max;
}

function Sayici(ilkSayi) {
/**
* [Görev 4A] Sayici bir sayaç oluşturur
* @param {number} ilkSayi - Sayacin ilk değeri
*/

// ✨ gerekli propları ekleyin

this.initial = ilkSayi
this.first = true


/**
* [Görev 4B] asagiSay metodu sıfıra doğru sayar
Expand All @@ -57,6 +71,17 @@ function Sayici(ilkSayi) {
*/
this.asagiSay = () => {
// ✨ kodlar buraya
if (!this.first) {
if (this.initial <= 0) {
return 0
} else {
this.initial = this.initial - 1
return this.initial
}
} else {
this.first = false
return this.initial
}
}
}

Expand All @@ -66,6 +91,8 @@ function Mevsimler() {
*/

// ✨ gerekli propları ekleyin
this.mevsimler = ['yaz', 'sonbahar', 'kış', 'ilkbahar']
this.count = 0

/**
* [Görev 5B] sonraki metodu bir sonraki mevsimi gösterir
Expand All @@ -81,22 +108,34 @@ function Mevsimler() {
*/
this.sonraki = () => {
// ✨ kodlar buraya
let mevsim = ""

if (this.count > 3) {
this.count = this.count % 4
mevsim = this.mevsimler[this.count]
} else {
mevsim = this.mevsimler[this.count]
}
this.count++
return mevsim;
}
}

function Araba(/*kodlar buraya */) {
function Araba(name, depoBenzin, kml) {
/**
* [Görev 6A] Araba 3 argüman alarak bir araba nesnesi oluşturur
* @param {string} isim - arabanın ismi
* @param {number} depo - benzin deposu kapasitesi
* @param {number} kml - arabanın litre başına kat edebileceği km yol
*/

this.odometer = 0 // araba 0 kilometrede yüklenecek
this.depo = depoBenzin // araba full depoyla yüklenecek
// ✨ gerekli propları ekleyin


this.odometer = 0 // araba 0 kilometrede yüklenecek
this.depo = depoBenzin // araba full depoyla yüklenecek
// ✨ gerekli propları ekleyin
this.name = name
this.km = kml
this.toplamYol = 0


/**
* [Görev 6B] sur metodu odometera km ekler ve aynı oranda depodan benzin tüketir
Expand All @@ -113,6 +152,18 @@ function Araba(/*kodlar buraya */) {
*/
this.sur = (gidilecekyol) => {
// ✨ kodlar buraya
// if (this.depo <= 0) {
// this.depo = 0
// }
if (gidilecekyol > (this.km * this.depo)) {
this.toplamYol += this.km * this.depo
this.depo = this.depo - ((this.km * this.depo) / this.km)
} else {
this.toplamYol += gidilecekyol
this.depo = this.depo - (gidilecekyol / this.km)
}

return this.toplamYol
}

/**
Expand All @@ -128,6 +179,11 @@ function Araba(/*kodlar buraya */) {
*/
this.benzinal = (litre) => {
// ✨ kodlar buraya
this.depo += litre
if (this.depo > depoBenzin) {
this.depo = depoBenzin
}
return this.depo * this.km
}
}

Expand All @@ -144,8 +200,9 @@ function Araba(/*kodlar buraya */) {
* // sonuç false
* })
*/
function asenkronCiftSayi(sayi) {
async function asenkronCiftSayi(sayi) {
// ✨ implement
return sayi % 2 === 0
}

module.exports = {
Expand All @@ -156,4 +213,4 @@ module.exports = {
Sayici,
Mevsimler,
Araba,
}
}
135 changes: 116 additions & 19 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,146 @@ describe('[Görev 1] nesneyiTrimle', () => {
})

describe('[Görev 2] verileniTrimle', () => {
// test('[3] verilen propu trimliyor', () => {})
// test('[4] verilen dışındaki proplar trimlenmeden döndürülüyor', () => {})
let actual;
let prop;
const input = { foo: ' foo ', bar: 'bar ', baz: ' baz' }
beforeEach(() => {
prop = "foo"
actual = utils.verileniTrimle(input, prop)
})
test('[3] verilen propu trimliyor', () => {
expect(actual[prop]).toEqual(actual[prop].trim())
})
test('[4] verilen dışındaki proplar trimlenmeden döndürülüyor', () => {
expect(actual['bar']).toEqual(input['bar'])
})
})

describe('[Görev 3] enBuyukTamsayiyiBul', () => {
// test('[5] bir dizi nesne içindeki en büyük tamsayiyi döndürüyor { tamsayi: 2 }', () => {})
const tamsayilar = [{ tamsayi: 1 }, { tamsayi: 3 }, { tamsayi: 2 }, { tamsayi: 5 }];
test('[5] bir dizi nesne içindeki en büyük tamsayiyi döndürüyor { tamsayi: 2 }', () => {
const max = utils.enBuyukTamsayiyiBul(tamsayilar)
expect(max).toBe(5);
})
})

describe('[Görev 4] Sayici', () => {
let sayici
beforeEach(() => {
sayici = new utils.Sayici(3) // her test yeni bir sayı ile başlatılıyor
})
// test('[6] sayici.asagiSay ilk çağırılışında başlangıç sayışını yapıyor', () => {})
// test('[7] sayici.asagiSay İKİNCİ çağırılışında başlangıç eksi 1 sayıyor', () => {})
// test('[8] sayıcı sonunda sıfıra ulaşır ama daha aşağı saymaz', () => {})
test('[6] sayici.asagiSay ilk çağırılışında başlangıç sayışını yapıyor', () => {
let sayi = sayici.asagiSay()
expect(sayi).toBe(3)
})
test('[7] sayici.asagiSay İKİNCİ çağırılışında başlangıç eksi 1 sayıyor', () => {
let sayi = sayici.asagiSay()
sayi = sayici.asagiSay()
expect(sayi).toBe(2)
})
test('[8] sayıcı sonunda sıfıra ulaşır ama daha aşağı saymaz', () => {
let sayi = sayici.asagiSay()
sayi = sayici.asagiSay()
sayi = sayici.asagiSay()
sayi = sayici.asagiSay()
sayi = sayici.asagiSay()
expect(sayi).toBe(0)
})
})

describe('[Görev 5] Mevsimler', () => {
let mevsimler
beforeEach(() => {
mevsimler = new utils.Mevsimler() // her test yeni bir mevsimle başlar
})
// test('[9] mevsimler.sonraki İLK çağırılışında "yaz" döndürüyor', () => {})
// test('[10] mevsimler.sonraki İKİNCİ çağırılışında "sonbahar" döndürüyor', () => {})
// test('[11] mevsimler.sonraki ÜÇÜNCÜ çağırılışında "kış" döndürüyor', () => {})
// test('[12] mevsimler.sonraki DÖRDÜNCÜ çağırılışında "ilkbahar" döndürüyor', () => {})
// test('[13] mevsimler.sonraki BEŞİNCİ çağırılışında "yaz" döndürüyor', () => {})
// test('[14] mevsimler.sonraki KIRKINCI çağırılışında "ilkbahar" döndürüyor', () => {})
test('[9] mevsimler.sonraki İLK çağırılışında "yaz" döndürüyor', () => {
expect(mevsimler.sonraki()).toBe('yaz')
})
test('[10] mevsimler.sonraki İKİNCİ çağırılışında "sonbahar" döndürüyor', () => {
let mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
expect(mevsim).toBe('sonbahar')
})
test('[11] mevsimler.sonraki ÜÇÜNCÜ çağırılışında "kış" döndürüyor', () => {
let mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
expect(mevsim).toBe('kış')
})
test('[12] mevsimler.sonraki DÖRDÜNCÜ çağırılışında "ilkbahar" döndürüyor', () => {
let mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
expect(mevsim).toBe('ilkbahar')
})
test('[13] mevsimler.sonraki BEŞİNCİ çağırılışında "yaz" döndürüyor', () => {
let mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
mevsim = mevsimler.sonraki()
expect(mevsim).toBe('yaz')
})
test('[14] mevsimler.sonraki KIRKINCI çağırılışında "ilkbahar" döndürüyor', () => {
let mevsim = mevsimler.sonraki()
for (let i = 0; i < 39; i++) {
mevsim = mevsimler.sonraki()
}
expect(mevsim).toBe("ilkbahar")
})
})

describe('[Görev 6] Araba', () => {
let focus
beforeEach(() => {
focus = new utils.Araba('focus', 20, 30) // her test yeni bir araba oluşturur
})
// test('[15] arabayı sürünce güncellenmiş odometer döndürüyor', () => {})
// test('[16] arabayı sürmek benzin tüketiyor', () => {})
// test('[17] benzinalma arabayı sürmeye izin veriyor', () => {})
// test('[18] dolu depoya benzin alma etki etmiyor', () => {})
test('[15] arabayı sürünce güncellenmiş odometer döndürüyor', () => {
let total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(200)
total = focus.sur(200)
expect(total).toBe(600)
})
test('[16] arabayı sürmek benzin tüketiyor', () => {
let total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(200)
total = focus.sur(200)
expect(focus.depo).toBe(0)
})
test('[17] benzinalma arabayı sürmeye izin veriyor', () => {
let total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(200)
total = focus.sur(200)
focus.benzinal(10)
total = focus.sur(200)
total = focus.sur(200)
expect(total).toBe(900)
})
test('[18] dolu depoya benzin alma etki etmiyor', () => {
let total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(100)
total = focus.sur(200)
total = focus.sur(200)
focus.benzinal(20)
expect(focus.depo).toBe(20)
focus.benzinal(20)
expect(focus.depo).toBe(20)
})
})

describe('[Görev 7] asenkronCiftSayi', () => {
// test('[19] bir çift sayı verilirse true çözümlüyor', () => {})
// test('[20] tek sayı verilirse false çözümlüyor', () => {})
})
test('[19] bir çift sayı verilirse true çözümlüyor', async () => {
expect(await utils.asenkronCiftSayi(2)).toBe(true)
})
test('[20] tek sayı verilirse false çözümlüyor', async () => {
expect(await utils.asenkronCiftSayi(1)).toBe(false)
})
})