Alternative to if else statement

I need to find an alternative way for this (if else statement) :


    if(representatives.indexOf(word) == -1){  
        representatives.add(word);    

    }
    else if(repeatWords.indexOf(word) == -1){  
        repeatWords.add(word); }

Answers


Try with contains as devid explained. contains is a function of list to checkout object contains or not. so you have to modify code like below:

 if(!representatives.contains(word)){  
        representatives.add(word);    

    }
    else if(!repeatWords.contains(word)){  
        repeatWords.add(word); }

It check if list don't contain object then add it. otherwise; everything seems ok!!.


Need Your Help

The main thread locked when fetching images from parse with semaphore

swift parse-platform ios4 semaphore

I have a very big problem. I use Parse cloud system. When i fetch images with using "dispatch_semaphore" from parse, the main thread is locked. However, i think, i don't use main thread when fetching

PresentModalViewController with some frame

iphone ios presentmodalviewcontroller uimodalpresentationstyle

I want to present a modalViewController with a small frame and at the center of the view.