MCPcopy Create free account
hub / github.com/codecombat/codecombat / getChallengers

Method getChallengers

app/views/ladder/LadderPlayModal.js:207–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205 // Choosing challengers
206
207 getChallengers () {
208 // make an object of challengers to everything needed to link to them
209 let easyInfo, hardInfo, mediumInfo
210 let m
211 const challengers = {}
212 if (this.challengersCollection) {
213 easyInfo = this.challengeInfoFromSession(this.challengersCollection.easyPlayer.models[0])
214 mediumInfo = this.challengeInfoFromSession(this.challengersCollection.mediumPlayer.models[0])
215 hardInfo = this.challengeInfoFromSession(this.challengersCollection.hardPlayer.models[0])
216 } else {
217 let matches
218 if (this.options.league) {
219 matches = _.find(this.session?.get('leagues'), { leagueID: this.options.league.id })?.stats.matches
220 } else {
221 matches = this.session?.get('matches')
222 }
223 const won = ((() => {
224 const result = []
225 for (m of matches) {
226 if (m.metrics.rank < m.opponents[0].metrics.rank) {
227 result.push(m)
228 }
229 }
230 return result
231 })())
232 const lost = ((() => {
233 const result1 = []
234 for (m of matches) {
235 if (m.metrics.rank > m.opponents[0].metrics.rank) {
236 result1.push(m)
237 }
238 }
239 return result1
240 })())
241 const tied = ((() => {
242 const result2 = []
243 for (m of matches) {
244 if (m.metrics.rank === m.opponents[0].metrics.rank) {
245 result2.push(m)
246 }
247 }
248 return result2
249 })())
250 easyInfo = this.challengeInfoFromMatches(won)
251 mediumInfo = this.challengeInfoFromMatches(tied)
252 hardInfo = this.challengeInfoFromMatches(lost)
253 }
254 this.addChallenger(easyInfo, challengers, 'easy')
255 this.addChallenger(mediumInfo, challengers, 'medium')
256 this.addChallenger(hardInfo, challengers, 'hard')
257 return challengers
258 }
259
260 addChallenger (info, challengers, title) {
261 // check for duplicates first

Callers 1

loadNamesMethod · 0.95

Calls 4

addChallengerMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected