開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta 6
- Swift (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 11(Storing Data Using Other Collection Types)、11.8(Exercises) 2.をSwiftで考えてみる。
11.8(Exercises) 2.
コード(Xcode)
main.swift
// // main.swift // sample2 // // Created by kamimura on 10/4/14. // Copyright (c) 2014 kamimura. All rights reserved. // import Foundation func matingPairs(males:[String], females:[String]) -> [(String, String)] { var pairs:[(String, String)] = [] for i in 0..<males.count { let male:String = males[i] let female:String = females[i] let pair:(String, String) = (male, female) pairs.append(pair) } return pairs } let males:[String] = ["a", "b", "c", "d", "e"] let females:[String] = ["A", "B", "C", "D", "E"] println(matingPairs(males, females))
入出力結果(Console Output)
[(a, A), (b, B), (c, C), (d, D), (e, E)] Program ended with exit code: 0
0 コメント:
コメントを投稿