LoginSignup
1
0

More than 5 years have passed since last update.

Swift:n番目を先頭としたループになるような配列ソート

Last updated at Posted at 2018-07-22

はじめに

[A, B, C, D, E, F, G][C, D, E, F, G, A, B]のようにn番目を先頭にして、全体としてはループしているような配列を取得したい場合があったため、方法を考えた.

方法

let array = ["A", "B", "C", "D", "E", "F", "G"]

let n: Int = 3
let newArray = Array(d.dropFirst(n)) + Array(d.prefix(n))

Swift.print(newArray) // -> ["D", "E", "F", "G", "A", "B", "C"]

こんな感じ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0