Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions iOS Algs.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import UIKit

func tr(from: String, to: String, test: String) -> String {
var fromArray = Array(from.characters)
var toArray = Array(to.characters)
let testArray = Array(test.characters)
var testDictionary: [String : String] = [:]
var stupidNewArray: [String] = []
var result: String = ""
if fromArray.count != toArray.count {
return "Bad from/to string"
}
for char in 0..<fromArray.count {
testDictionary[String(fromArray[char])] = String(toArray[char])
}

for char in testArray {
if testDictionary.keys.contains(String(char)) {
stupidNewArray.append(testDictionary[String(char)]!)
}
else {
stupidNewArray.append(String(char))
}
}
for letter in stupidNewArray {
result += letter
}
return result
}
tr(from: "1a", to: "a1", test: "aax11")

//tr("1a","a1","aax11") => "11xaa"
4 changes: 4 additions & 0 deletions iOS Algs.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.