Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raviLakhtariya/482b5adf9203fd01227fb3e41a16a1f4 to your computer and use it in GitHub Desktop.
Save raviLakhtariya/482b5adf9203fd01227fb3e41a16a1f4 to your computer and use it in GitHub Desktop.
now i have one array like = [1,2,3,4,5,6,7] and user will input the value like 3 then we first search the index of value, which entered by user...and we generate new array like = [3,4,5,6,7,1,2]
class ViewController: UIViewController {
var array = ["R","a","v","i","i","o","s"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
getNewArray(input: "v")
getNewArray1(input: "v")
}
func getNewArray(input:String){
var index = array.firstIndex(of: input)!
var arra1 : [String] = []
for i in index..<array.count{
arra1.append(array[i])
}
for i in 0..<index{
arra1.append(array[i])
}
print(arra1)
}
func getNewArray1(input:String){
var index = array.firstIndex(of: input)!
var arra1 : [String] = []
var value = index
for i in 0..<array.count{
if value == array.count{
value = 0
}
arra1.append(array[value])
value += 1
}
print(arra1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment