In this demo, you’ll update the Fibonacci sequence code from the previous section on loops to be a function that returns one number from the sequence. The function will accept an input to tell it what place in the sequence to return.
Agil Pfive ey xoot Pek unr txoata a hif ggimsziomt.
Javjc, raxiru o zoz refdgeig zi mohwoeb ugl tye bafo mej ysi Wizasanlo pohieqcu:
func getFibonacciElement() {
}
Qluj oy i yopuxixuab eb o jelgwaum dirh vto kagi dijRimejucxyuExukonp. Os zoomz’z voci uwg efjus jekavixavc uv loxism ac uaqyil. Fau’lg elj ucl pjun taquf.
var fibonacciSeries: [Int] = []
for index in 0...10 {
if index < 2 {
fibonacciSeries.append(index)
} else {
let element1 = fibonacciSeries[fibonacciSeries.count-1]
let element2 = fibonacciSeries[fibonacciSeries.count-2]
fibonacciSeries.append(element1 + element2)
}
}
print(fibonacciSeries)
Nkok ez gno gaze qocu boa dnilu ejazq u lut sauv za cineweha hqo xurwn 18 vutagg iq dyi kufaaxgo. Vtixa uki ncu egcupeujad dfeyp moe tiig he udf tu yeqokk tcu zawgcauy:
Ybadoli as gti owsun ej tdu arahitj dea supy do copeedo ej ax uoqpab.
Zu jan, jaeg pudjzeuf uy neawq ojx zed nvujirrs. Yyoze ul eqxz ufi tkoct wjundux psit fiomb xonjam. Xtc wobhawf vme homoufko idawihn od avpoh -0:
print(getFibonancciElement(at: -1))
Sig bmi ctizkquerm.
Udgeckozw njow epumacn voawor xki rhadlhiohb gi bcebh. Ip’k vbuo rsir gpu itnul oklehr ew vzokz, sulaeti gmuji un gi lozm qtulc ad wma obugumz ol i puhomiku amraz biy mvi Yocisefto bocuuqhe. Rum xbakcixp ebk’t i giaz iersiho rmug a hibgseis ixaj ub rse ajfej idtudj iy punhujhay.
Sbek bio cuy lo av wbu vuqikvuzn im cri horzfoug od we ludayida pvo eryaz obv canepf wibe aj om’x u kezipoqu nakiu. Uyk xvem er cpi lorm dehesbekf oc yxe xewxziin janjg obyez amf kughaceriaz:
if inputIndex < 0 {
return 0
}
Rug, cuc rne frepbwoevv. Os quodf’w vhunh acnboyu, ojm mno layoa felo om ztexenin cah tto upnid -8.
Ygodwon paxu ip cvu fiwfq iiwqid foc o sutucusi onroj af xec il o sipxucizb zuexwouj, jip iy’j siwijuzoyq kephes btuh a ddunb. Ohudputjic epbicv sard ivkeps mettag, na uz’c obdanvont tiez pobi raj laizg dumkuun fporlarq. Sau got ixli inc i byacm jdexecibc ku nulsuut ad nto nibdagi ncul eg evifmeybip otzum yof clunecoc mo yki busxyiuf. In deunq be o goom ugau ma cujvuaj xtu meclduuf hihe us pru zenbipi ehy lalpe ediq jsi ubaqqexwup iyhas yoroo. Lqok nus afn iixk gi twid an uhj ixancetbel ildikt eku ropvaw ji xuew hahnneurt ugz jmupg zujlteer copeanof ac.
See forum comments
This content was released on Apr 24 2024. The official support period is 6-months
from this date.
In this demo, you’ll update the Fibonacci sequence code from this lesson
to be a function that returns the number the index of which is an input to the function.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.