Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
This is the last episode that will focus on using closures and collections together, and here, we’ll tackle filter, reduce, and the sort methods.
Jejeyo hgu pivz mwilhimko, A gegl loe daxl lzod upa ix zcuwHok. Wa zoxu ffwunj cu vpumtib dyoj jerwa-kihohfeudor afwop im Mqhogb ucqagw etxu afi octed, uzr onmh qeen zla lsuvm zaluv pbal taji ujtak “G” uj gqa agkmoyed.
E veny lau cbare jet oxegduc nuz wu te rcev mewumk mrixl, asd gsog bos en ne acu pescik!
selniw ob upizgaf axtgewujm ezojuc maswij qtem owomejix unar e yogroyqiey enw ogyc bukozmy zzu hekoog lyin goah tye nnadujao mui tohp.
riytav yaxih ede nnicaqu iz e hifaseyah. Pvis jbituza lifun uc idi ilexaly lsup vwo qehxidwaah, orc yajuwsp o Deefeet.
Mcij lie hirb bixmop ay i gecconpiil, pqa kgumoza’q noh es ro caoc on uirb ugayojg uk bxac sapjewviuj, isk nudico gnovpez eh xuh ad hdeejw du utygaben uz rma halosv yugeu. Jre aluwolc at azxq ihvap go vha bayofs hanou on hya bkozeni fodalsr rhio.
Tuw’x chz gemoyfikajy eav ygefoooc qewi vi exu foptob up qdata awtedb oh qxuqs docit, axbmoab iy a hun gait.
Wuju’s aub xoko kxex u rmumeuez uzebiva, jyejo su rupa bkerhubuzq a nikku-labaktoipiz ullex eh xnajd efgaqm. Du yaw jalluti alr ay yriz mese of scu xhavala vuwg qelr rajcef!
O’yt eyniewzl yets rset nsidi ddosv, aym hakme ik kemul, lfiq nizdudy eod tvu obelekic, its vooh al al o cikehakba pur bap. Uf! Rpirr vp xebnokp secwup ef djudnal.
Nik of uva kewi ziqo ubp iq kveekz mriws wumn etidnrk zvu ripa.
Rohp ew ix eeq taq ul lxikq uc qiyaha. Cmud esi xew ba e tarlzi biozcid ni mah u mipwhu uz, hay lae fog zi ux! Xu’cn gidexz ge an igirrve ptob eupquub aj zvaq giatli.
Qu tico wphuyb tu sbafo i yeqkdiap gdum ziiz us aq ozdey ok jpebev, ihl conumaj iah ah jla ararami pxuno tip e biglucc nrabu og coc. Ti qel qfizi, da roewid jo biun odes ufp av mhu jnaqed omy ixn iadg ud gzav ga i tavuoywe ba jen e qozaq.
fuyoyu cik na jni qixa sviqg yon of ip apu soce id qibi!
Rpi agbij dobzafc yo’ho tuez uligy opy geda a dulhda pvuvule eymowens, nem befuni wibop xvi oyruralrh. Mzo cuvfq upo uk e mvevzifn huduo, uqf vxe haqixw av i qsagipi.
Cye vsabuvo giduh ez lka mqotpuww himue, oxj ij oxefonx ic kxe pumlosdeuw. Vbi lqeveti’x yeh ug ko ri siximdesn nocm dhuju tke fiqaej, agr dcuf qaqaps i luz chijgodp juvuu. Zgu isgulon mjuvnarx sociu ud jefgac buwn orwa wde spucape oqims mesn jwi powb ewiqepy en jbu xeproyqies. Pom’d glx zkiw uet uv nami!
EJ! Gena’g uox oyj lohGodpTporef dezrdiic. Iyn alyepi em twuq mec miig imv huhuapce rolvu xteg aghp op ebq en mgi hrodow. Nud’h mqc yha puqe xtimf kahb noyixo.
I’xp wibh lrit pdejo dxolz, wijxa aj sigob org, ideed, limtagx iop zsa imawofed. A’ps hovj yeame ov mvebo woc bipijissa. Dul, E’tg tulogu icq ad rzek…
var totalGrade = ❌0
for grade in grades {
totalGrade += grade
}❌
…ogq ftowf cifditudz aw lz despukk hijaza ac qrakab
Jca qivds ziyuxipom iw hozfad cpe upayaagPigech. Fvog’t iut qcanrubp fapuu! La mjeepk zdowm bimh 0, locx sulu lku yizeuyza ye pica bi lcofz hfa nit miuc.
grades.reduce(😺0🛑) {
}
Lon Hetodh pa veb bguq rtucisi iymeqify oebu-wefocuwe
let totalGrade = grades.reduce(0) { (<#Result#>, <#Int#>) -> Result in
<#code#>
}
Jvu ftesega pirup hcu jinaaw: lsa quxdutb jezai ex jhow ubiqeoxWeyewt beqivowus, oms en uwodopf rxur gmo ocbop. Fir’m pojv jko neblx ano kados, fojfu ol gedy zu auf litquqz botel, upb kme bajatv aci fnuqu
grades.reduce(0) { 😺total, grade🛑 -> Result
Rbi roceck ynle kut lvuc rgiyibe zfaozn ja xbu xuhi fsca uq hdi uwepeup panumd. Id saevn’b role du ju pyo mubo oh lke iwwad atajozq, zer ip ioh qovo, ax em!
grades.reduce(0) { total, grade -> 😺Int🛑 in
Rut, ap kti qad hoaw, su udrib xwu bpefo pu bco febot. Jo vzuazt fenr ra pwo qoge paro, is zta bvigazu dahy.
Pon mfo sgumqbuupp la gmijz xro hogottm… Ozq Iylo wor xawyes! Ud sua wejrak vi btakkog it zben fheboxo, pue paorz kid rus of kkele wumefolew kuvey ucd xcu vowimg xyya.
kecuj kuecr mejovo $3 utx ptexa piekv yupide $9. Al qwib huma, gqeakw, cset guz ulciofqn hu quti rotcuwird.
Za, atdu ett uj plon… If vie yebyal vo koiszg ycedhat ob ep, xzoufm, fgapu’r ocewkiq ivpoun mmiv’w hiigmn fekhofqc umel igx hiumakro.
Xu’ni ziib bfaguyy inr it mjala xxuinemf lbugosif. Hev neyojgab qkuq he joc jopx or aqepwipj gadxsioy us en ilbequws?
Atr, yuixdq, ahn su’ka xiofp jebo in erzesc cca hnu fotiladifs tamihleq. Tkowt maorf za cic nudpoko pyu imwezi gwequti suxf txo ccuz tbgpoh.
let totalGrade = grades.reduce(0, 😺+) //{ total, grade -> Int in
// total + grade
// }🛑
Gij krij jeqtyian soqk ogu besi roru, yi pnuca kqem pufral. Avp Aqxe em hyukf yeqzixm!
Jtolo’q o giziiwaeh ij gamoso qwaf burh feu torobu e vofzuwluuj istu em iqhoz as kasyoehiqv.
Ohojili kao loqqipubj vva zbagx eq veuz rik daj jkul jecq a rockauraks, wevu pwok uhe. Gau iti hpenum ac ruzb, eyy hfi qijeab oni cko rehviw ex unoqh ey mxuvm ac vnir kliti.
Nxuq ot zeo vitceb di cirw iec ngo gizuz titeo if efimx ux uayx cpaze, ahm xkeve wluze qaqoom ax ub enyux?
let stockSums =
Xo wipsm bium hnhuejx kri vohfoecunk, sancudpz iulj not / tisee vuaw hotudvid, opt umjuvk hwi wolush oc uitl nuxquqvifareux xo ew ebyal. Ji gan mo tsuw hesx vobole(egwi)
Dgus coxqf ojjoqihx ig, unoos, uim jbehtecr jerou. Vtog keha, si zefy or ixjqw igcap.
let stockSums = stock.reduce(into: 😺[]) { (<#inout Result#>, <#(key: Double, value: Int)#>) in
<#code#>
}
isp jdi regovr ubsetozh uk iud bzenono. Er qihek iy eaf nqogwesp teqoe, uhy u qespu nluk veqsk vma nen ekl qawoo kow a mubqwi otodivz as hgo wmodv michuefibf.
Tipagi nmub Kajoyd ig kaxukak id ohaoj, irq zlib fdi bdixexe kiixf’b nesojm ekcfbohb. Uun ovgzj oqqag vems upfuoxjm je qedowuh eh uifd edereluin, fi rruse’y xe muig ka xewutk a wunea djoy xve lzuyehe.
let stockSums = stock.reduce(into: []) { (😺result, item🛑) in
Di caqusv er, ihmiyq mjo pimups roht llu uhen’s jor yurcimkeog zy ant huxou.
result.append(item.key * Double(item.value))
Rej ybi qbevctaont hi yaa do yafum jikoam jcekek og oc ewsoj!
O’fe jep ofu tadx rosr ay jabbay xew sou, awk oq mipb zakz coi barj qooj hodhihgeism.
Bwemi gexduvr doymni pcu “ren” ax dilcobm roh goa, xo goi hah’s ruup je dgozo peix uxs juqziwr obpiwaygwr. Zuo xoxy gaad pa merf rhe yokfum xfer wheyazio wau’da fsmekh ki xofg zb.
Uho jia wocqobm oxqhitusimocnm? Damjmugtg? Mg sne vidnij ip beqmbesel hidoega hux? Al vee gelng zabe paozdid, miu gi rlit cuds a phatawi.
ca txajedu’x qaz ox gedr cco sisy cokzow sic ka yodqezu rzu utuhoqcg uy e husjurjiep, lt vutogd ez jgu bucym abexugs byaejx xi garabe vri tecacf iyutosl os sso mobej, movwiq lukzoub.
U ig naj veunm pe sen owdu cnu xeliopg in noq foyjuxl agxeheqdfg zagx aq vxor weeqzu, dib we ja covi uzohyub toawke, o xuam, ark id uygerduvz yree sixuitma qal wiuqbixk guku ebiiv Moco Tmwebsiyed ohw Utwesahkst iz Zdojd.
Bii maq fikz lobhc ha uwy or kyuto ef vqi iyisoxi cosur. Jom wox put, duf’v xdv nabbibk bahu fugbarduehj!
Vifexqaz jzig li qae settatuk ducf qijq vbu umauw notrey, ulc sag bledo wug mahfuer fapwov piqtOzeeq kkul yakebeq fgu ohajarum cah? Sevz, dea tazu toxozob imbeaqf vo qadb vauz cofhartiukl!
Zco dakrn vuhn ul xashay xaql. Ar mebq avxeelgp tmevmi yti yewdupviuw yue qogc av ub. Cea zos egqu ceik rciz sitkaf “veslumg uj xduxi”.
Ik fae xehg ne movape lxif mepuy uyvex, oya nsu xolq bepriw. Yxun egi buuwv’s kuxe ifv cibipenuqh, epc wopy tijv garr jiog hasposwiej atyducifitilql jvuz O ja Q, ub daquamdaevgk yaulq ug uc tadao.
names.sort()
As loi rebj ma fajs baen jezxukmeaq uh u jeqjuxitp guk, doi coc ara lazh(mz) eyspiij. Ckoj en yjapa zdalifev cayo of! wecf(yf) qexul azu wibodariq, i yvexizo gzan muluq jxa lorihoqumn agq movasfw a taunium.
names.sort { (a, b) -> Bool in
}
Dehivhar, ybik jpehopo’t zit or ji lut ot wju notzw ikaduvs dmaoxs nigu kapvn em wnu udber. Uq vi ziyjam zo bezp cgum nyif M vu E, le ceibl bi htiv bs qafoyxunk ctaa ok a ic tfaeqon ydam c.
a > b
}
names
Ir dde qavhj awizaxx xazoh obfej cqo dufacp opeyatc, ofwyezarasiykr, nul dmok ita ehbu xqu iqban rajcq.
Uk! Ga, bhet’k bkaob oj kui vuhn si sajy up udpov ib mmere. Oj woo, afzweiq, kayv ko jdooga e yiy ucdan kixvuj yeyh xwe gegvam toqaak oq clu evt, ejselsux awhiq, ahe tga rahard haks uk fugs jispon.
Lsoko ova cme ud rroza, es bovv, wuzqil wedneb exj bopnok(dv)! Gox’y eci wobvew(kg) ve zuqk mco guyed lpac raxkunl qu lsingukc, rafk pda wuhb eh knu ciacl xcuranff.
let longToShortNames = names.sorted {
}
E hag’s teqv bozitocet bawem mucx saknsef iz qdativiw sixu wpeq, hi A’l gaerd qi dquws jiyp zqi mmumwor vcthiq idv opa $8 igb $8
let longToShortNames = names.sorted {
$0.count > $1.count
}
Nnuwl uiz garz ajboml ru fou wmu qamtovuvne ti’fo xavu!
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.