開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta
- Swift (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 8(Storing Collections of Data Using Array)、8.9(Exercises) 4-a, b, c, d, e, f.をSwiftで考えてみる。
8.9(Exercises) 4-a, b, c, d, e, f.
コード(Xcode)
main.swift
// // main.swift // sample4 // // Created by kamimura on 8/23/14. // Copyright (c) 2014 kamimura. All rights reserved. // import Foundation var ids = [4353, 2314, 2956, 3382, 9362, 3900] println(ids) println("a.") for i in 0..<ids.count { if ids[i] == 3382 { ids.removeAtIndex(i) break } } println(ids) println("b.") for i in 0..<ids.count { if ids[i] == 9362 { println(i) break } } println("c.") for i in 0..<ids.count { if ids[i] == 9362 { ids.insert(4499, atIndex: i + 1) break } } println(ids) println("d.") ids.extend([5566, 1830]) println(ids) println("e.") ids = ids.reverse() println(ids) println("f.") ids.sort({(a, b) -> Bool in a < b}) println(ids)
入出力結果(Console Output)
[4353, 2314, 2956, 3382, 9362, 3900] a. [4353, 2314, 2956, 9362, 3900] b. 3 c. [4353, 2314, 2956, 9362, 4499, 3900] d. [4353, 2314, 2956, 9362, 4499, 3900, 5566, 1830] e. [1830, 5566, 3900, 4499, 9362, 2956, 2314, 4353] f. [1830, 2314, 2956, 3900, 4353, 4499, 5566, 9362] Program ended with exit code: 0
0 コメント:
コメントを投稿