// есть массив нужно отнять от первого второе и от второго третье и тд и записать в новый массив var s = [1,2,3,4,5,6,7,8] //в массив по хорошему приходит разное количество значений for i in s { s[i] = s[i-2] - s[i-1] } 
  • and you can immediately sample the result. not entirely clear - take away the second from the first and write to the first? then from the second to the third and write to the second? - Max Mikheyenko
  • and what to do with the latter, since there is no next - Max Mikheyenko

1 answer 1

 var s1 = [1,2,3,4,5,6,7,8] var s2 = [Int]() for index in 0..<s1.count-1 { s2.append(s1[index]-s1[index+1]) }