Skip to content

Commit

Permalink
Merge pull request soapyigu#238 from gandhimena/patch-1
Browse files Browse the repository at this point in the history
return a constant value with reduce
  • Loading branch information
soapyigu authored Sep 2, 2019
2 parents 94fdc53 + 7ee849c commit cac7f7a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Array/SortArrayByParity.swift
Original file line number Diff line number Diff line change
@@ -8,11 +8,9 @@

class SortArrayByParity {
func sortArrayByParity(_ A: [Int]) -> [Int] {
var outputArray = [Int]()
for (_,value) in A.enumerated(){
outputArray.insert(value, at: value % 2 == 0 ? 0 : outputArray.count)
return A.enumerated().reduce(into: [Int]()) { (acc, arg) in
let (_, value) = arg
acc.insert(value, at: value.isMultiple(of: 2) ? 0 : acc.count)
}

return outputArray
}
}

0 comments on commit cac7f7a

Please sign in to comment.