Stop gninnipS My sdroW!

JavaScript

function spinWords(sentence) {
  return sentence.split(' ').map(word => word.length > 4 ? word.split('').reverse().join('') : word).join(' ');
}

CoffeeScript

spinWords = (string) ->
  return `string.split(' ').map(word => word.length > 4 ? word.split('').reverse().join('') : word).join(' ')`

Python

def spin_words(sentence):
    sentence = sentence.split(' ')
    for i in range(len(sentence)):
        sentence[i] = reverse(sentence[i])
    return ' '.join(sentence)

def reverse(word):
    if len(word) > 4:
        return word[::-1]
    return word

TypeScript

export class Kata {
  static spinWords(words: string) {
    return words.split(' ').map(word => word.length > 4 ? word.split('').reverse().join('') : word).join(' ');
  }
}

Tags

  1. javascript (Private)
  2. coffeescript (Private)
  3. python (Private)
  4. typescript (Private)
  5. 6-kyu (Private)
  6. codewars (Private)
  7. answer (Private)