From 851732ffe9527a6588b82f27f98e95b211de59d5 Mon Sep 17 00:00:00 2001 From: Mesfin Date: Tue, 30 Jun 2015 20:36:02 -0400 Subject: [PATCH] I am finished --- TestAssessment/Base.lproj/Main.storyboard | 6 +- TestAssessment/TestViewController.m | 186 ++++++++++++++-------- 2 files changed, 124 insertions(+), 68 deletions(-) diff --git a/TestAssessment/Base.lproj/Main.storyboard b/TestAssessment/Base.lproj/Main.storyboard index d912f9d..9b8e7ad 100644 --- a/TestAssessment/Base.lproj/Main.storyboard +++ b/TestAssessment/Base.lproj/Main.storyboard @@ -1,13 +1,13 @@ - + - + - + diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 013428d..077eff6 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -15,176 +15,232 @@ @implementation TestViewController /* - This method should return any positive NSInteger - (hint: cannot be 0) + This method should return any positive NSInteger + (hint: cannot be 0) */ -- (void)shouldReturnAPositiveNSInteger { - +- (NSInteger)shouldReturnAPositiveNSInteger { + return 5; } /* - This method should return any negative CGFloat - (hint: cannot be 0) + This method should return any negative CGFloat + (hint: cannot be 0) */ -- (void)shouldReturnANegativeCGFloat { - +- (CGFloat)shouldReturnANegativeCGFloat { + return -2.7; } /* - This method should return a falsy boolean - Falsey: Something which evaluates to FALSE. + This method should return a falsy boolean + Falsey: Something which evaluates to FALSE. */ -- (void)shouldReturnAFalseyBool { - +- (BOOL)shouldReturnAFalseyBool { + return NO; } /* - This method should return a single char from a - z + This method should return a single char from a - z */ -- (void)shouldReturnACharAtoZ { +- (char)shouldReturnACharAtoZ { + return 'm'; } /* - This method should return the sum of all numbers from - 0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99) + This method should return the sum of all numbers from + 0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99) */ - (NSInteger)shouldReturnSumOf0To100 { - return 0; + int sum=0; + for(int i=0;i<100;i++){ + sum += i; + } + return sum; } /* - Given a c array (int[]) and a count, return the sum of the numbers within the arr - (eg. arr[0] + arr[1] ...) + Given a c array (int[]) and a count, return the sum of the numbers within the arr + (eg. arr[0] + arr[1] ...) */ - (NSInteger)shouldReturnSumOfArrayValues:(int *)arr withSize:(int)count { - return 0; + int sum=0; + for(int i=0;i mikemikemikemikemike - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/ +/* + Given a string, return the string repeated x times + Example: mike, 5 => mikemikemikemikemike + https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/ */ - (NSString *)repeatString:(NSString *)str numberOfTimes:(NSInteger)x { - return @""; + + return [@"" stringByPaddingToLength:[str length]*x withString:str startingAtIndex:0]; + } // BONUS /* - Given an array of numbers, sum each number in the array UNTIL - the sum is greater than 1050. The returned value of this method - should never be greater than 1050. - (ex: [500, 500, 500] returns 1000) - (ex: [200, 500, 100, 400] returns 800) + Given an array of numbers, sum each number in the array UNTIL + the sum is greater than 1050. The returned value of this method + should never be greater than 1050. + (ex: [500, 500, 500] returns 1000) + (ex: [200, 500, 100, 400] returns 800) */ - (int)returnSumWhileSumIsLessThan1050:(int *)arr { - return 0; + int sum=0; + int i=0; + + while(true){ + sum += arr[i]; + if (sum > 1050) { + sum -= arr[i]; + break; + } + i++; + } + return sum; } @end