Created
August 4, 2016 04:19
-
-
Save hideki-a/f535d3ff139bc21769e7e75b6947d094 to your computer and use it in GitHub Desktop.
指定した順で配列の値を並べる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mtCategoryIds = [1,2,3,4,5,7,8,9] | |
var savedCategoriesOrder = [3,7,2,1,5,4,6] | |
var dispCategoryIds: [Int] = [] | |
for categoryId in savedCategoriesOrder { | |
if let index = mtCategoryIds.indexOf(categoryId) { | |
dispCategoryIds.append(categoryId) | |
mtCategoryIds.removeAtIndex(index) | |
} else { | |
if let index = savedCategoriesOrder.indexOf(categoryId) { | |
savedCategoriesOrder.removeAtIndex(index) | |
} | |
} | |
} | |
dispCategoryIds = dispCategoryIds + mtCategoryIds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment