Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
19
Task/Repeat-a-string/Swift/repeat-a-string-3.swift
Normal file
19
Task/Repeat-a-string/Swift/repeat-a-string-3.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extension String {
|
||||
func repeatBiterative(count: Int) -> String {
|
||||
var reduceCount = count
|
||||
var result = ""
|
||||
var doubled = self
|
||||
while reduceCount != 0 {
|
||||
if reduceCount & 1 == 1 {
|
||||
result.appendContentsOf(doubled)
|
||||
}
|
||||
reduceCount >>= 1
|
||||
if reduceCount != 0 {
|
||||
doubled.appendContentsOf(doubled)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
"He".repeatBiterative(5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue