UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 5 Find Bug Challenge

Forums > 100 Days of Swift

I am not able to produce the bug mentioned in the challenge!

3      

Hi Tatzati!

Have you tried doing it like this?:

Choose a word from the one in the title (an anagram). For example, if the word were sandbards, type 'Sand'. Then try adding 'sand' (the first one being uppercased is the important thing). Your app should have accepted both, while it shouln't work like this, as it is exactly the same word. Let me know if u managed to trigger the bug, and if u managed to solve it! Also, let me know if i'm not explaining myself very well as my english is not very good.

Hope it helps!

3      

Change the answer to lowercase using .lowercase even if the person enters in capital letters before checking if the answer is being answered before

3      

So the thing here is that solution to the bug was already provided by Paul on the submit function:

let lowerAnswer = answer.lowercased()

But in the wrap up section he hints that the error should be on:

usedWords.insert(answer, at: 0)

And this is what got me confused.

3      

@tatzati Well, let lowerAnswer = answer.lowercased() creates a constant where answer is always lowercased...

But we have to remember to use lowerAnswer while inserting the new submission (answer) into the usedWords array.

Just did this today! ;)

3      

@ageDiMasi, oh i see now. I had added the lowercassed version to the insert method so that is why i couldn't reproduce the bug :)

Cheers

3      

Solution for the problem:

userWords.insert(answer.lowercased(), at: 0)

4      

Hello!

Just to add another view, I think also the code below can work fine, leaving freedom to the user to use whichever case they want to use, while maintaining the logic of the game intact.

func isOriginal(word: String) -> Bool {

    let lowercaseArray = usedWords.map{$0.lowercased()}
    return !lowercaseArray.contains(word)

}

I am not sure if it is efficient or not, so I am also looking for another opinion, but it works :D

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.