Skip to content

Instantly share code, notes, and snippets.

View bradleyyin's full-sized avatar

BRADLEY YIN bradleyyin

View GitHub Profile
@bradleyyin
bradleyyin / codeChallengeWeek6.swift
Created August 14, 2019 15:39
iOS code challenge week 6
func expandNumber(_ num: Int) -> [Int] {
var number = num
var numbers: [Int] = []
let numString = String(num)
let numberOfDigit = num >= 0 ? numString.count : numString.count - 1
for i in 1...numberOfDigit {
let iDigit = number % Int(pow(10, Double(i)))
number -= iDigit
/* for a word to be rearrange to palindrome it will need to have even number of letters on all letters or except one letter
aabbcc or aabbc can both be rearrange to palindrome.
make a dictionary storing all the letters, if number of letters are all even or all even except one then return true, else return false.
*/
func isArrangeToPalindrome(string: String) -> Bool{
guard !string.isEmpty else {
return false
}
var dictionary : [Character : Int] = [:]
@bradleyyin
bradleyyin / ios week3 day 3 code challenge
Created July 24, 2019 15:43
ios week 3 day 3 code challenge
// loop through string with index, if found the first character, check subsequent characters
// assuming passing empty string in will return false
extension String {
func anotherContains (_ string: String) -> Bool{
if string.count > self.count || string.count == 0 {
return false
}
let lowercaseInput = string.lowercased()
let lowercaseSelf = self.lowercased()
@bradleyyin
bradleyyin / iOSCodeChallenge-Sprint02-02.swift
Created July 17, 2019 15:44
iOSCodeChallenge-Sprint02-02
/*
takes 2 int, sum and product -> smallest 2 positive Int x and y. x+y == sum, x*y == product
return x and y in array with smallest in front
return empty if no solution found
pseudo code:
make an empty array for storing answer
loop through 1 to sum /2 if sum is even, loop through 1 to sum/2 + 1 if sum is odd and find each complimentary number and store them in dictionary.
ex: sum = 6, go through 1~5 and dict = {1:5, 2:4, 3:3}
then go through the dict to find the key value pair that produce the product, add that into the array and break out the loop
@bradleyyin
bradleyyin / iOSMorningCodeChallenge-Sprint01-Challenge1.swift
Last active July 10, 2019 15:25
ios8 week 1 day 3 code challenge
//create a vowels string to compare if a character is a vowel
//then loop through the entire string and check if vowels contains each character
//if vowels has that character, then add 1 to the count.
//in the end, return the total count
//
func numberOfVowels(in string: String) -> Int {
var count = 0
let vowels = "aeiouAEIOU"
for character in string {