Skip to content

Conversation

marsikeda
Copy link

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

}

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
}
@sarahzinger
Copy link
Collaborator

cool solution! 💯 Do you think you'd be able to put your solution file into a solutions folder for the particular challenge? So for the tr problem there already is a solutions folder here: https://github.com/WomenWhoCodeNYC/Algorithms/tree/master/challenges/tr

If you move the file on your local machine to solutions folder and recommit it and push, it should update your pr automatically! If you run into any problems let me know and I can help out.

Nice job! 🥇

@marsikeda
Copy link
Author

marsikeda commented Jan 18, 2017 via email

@sarahzinger
Copy link
Collaborator

@MGTEI you can make it from the command line on your branch that you've made and your pull request will automatically update. Give it a shot and if it doesn't work as expected, don't worry just let me know, whatever happens we can fix it 😄 Way to go practicing github !🎈 Next time you make a pr you might want to check out this guide we made which might have some helpful hints!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants