Chapter 7 - Challenge Question

Hello I’m working on challenge(ing). I solved myself but have an unsolved question.

Here is my code. Added only code that i wrote.

let input = PublishSubject<String>()

// Add your code here
  input
    .skipWhile({ 
      print($0, $0 == "0")
      return $0 == 0 
    })
    .compactMap({ convert($0) })
    .take(10)
    .toArray()
    .map({ format($0) })
    .subscribe(onSuccess: {
      print($0)
    })
    .disposed(by: disposeBag)

2nd line’s skipWhile() is used meaning of skip before 0 includes 0. But here is the console.

--- Example of: Challenge 1 ---
 false
060-355-5121

In short, skipWhile() didn’t work after 1st Event emit.

I fixed it moving skipWhile() just below compactMap().

What happend?? These 2-way using skipWhile() different???

input.skipWhile({$0 == "0"}).compactMap({convert($0)}) // Using 1
input.compactMap({convert($0)}).skipWhile({$0 == 0}) // Using 2

Have a nice day! Thanks!!

@scotteg @icanzilb any suggestions?

This topic was automatically closed after 166 days. New replies are no longer allowed.