Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

d #33

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
24 changes: 23 additions & 1 deletion Tutorial/Tutorial.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,27 @@ let champs = try JSONSerialization.jsonObject(with: champsData!, options: [])
let selectedIndexes = try JSONSerialization.jsonObject(with: selectedIndexesData!, options: [])

// TODO: selectedIndexes는 챔피언 목록(champs)의 key 번호 들이다. selectedIndexes에 명시된 순서대로 챔피언들의 이름(name)을 나열하라
let names: [String] = []
var names: [String] = []

var champsDictArr = champs as! [[String:Any]]
let selectedIndexesIntArr: [Int] = selectedIndexes as! [Int]
let selectedIndexesStringArr: [String] = selectedIndexesIntArr.map { "\($0)" }

for champDict in champsDictArr {
let champKey = champDict["key"] as! String
print(champKey)
if selectedIndexesStringArr.contains(champKey) {
names.append(champDict["name"] as! String)
}
}

print(names)
names = []

(champs as! [[String:Any]]).filter { (selectedIndexes as! [Int]).map { "\($0)" }.contains($0["key"] as! String) }
.forEach { names.append($0["name"] as! String) }

print(names)

// forEach, filter, first/last(where:), reduce
// map, flatMap, compactMap