Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

A single word was successfully ase swapped

Featured Replies

I'm now working on the strange case problem. Write a function toWeirdCase (weirdcase in Ruby) that receives a string and returns it with all even indexed letters in each word upper cased and all odd indexed characters in each word lower cased. Because the indexing described above is zero-based, the zero-ith index is even, hence that letter should be capitalised.

The function was written by myself.

def to_weird_case(string):
    tot=""
    for i in range(len(string)):
        if i%2==0:
             tot+=string[i].upper()
        if i%2==1:
             tot+=string[i].lower()

    if string[i]==" " or i%2==1:
       to_weird_case(string[i:])
    return tot 

It correctly swaps the case of a single word, but it does not work for several words or a phrase. I considered using swapcase, but it swapped all the words in the sentences, which is undesirable.

So, by chance, I received this type:

toWeirdCase
 should return the correct value for a single word (8 of 8 Assertions)
 should return the correct value for multiple words
'ThIs iS A TeSt' should equal 'ThIs Is A TeSt'
'LoOkS LiKe yOu pAsSeD' should equal 'LoOkS LiKe YoU PaSsEd'
'ThIs iS ThE FiNaL TeSt cAsE' should equal 'ThIs Is ThE FiNaL TeSt CaSe'
'JuSt kIdDiNg' should equal 'JuSt KiDdInG'
'Ok fInE YoU ArE DoNe nOw' should equal 'Ok FiNe YoU ArE DoNe NoW'\

I saw an article that suggests dividing the sentence and applying the function to each word, but making all words uppercase. So, can somebody assist me?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.