Skip to content

Instantly share code, notes, and snippets.

@ViniciusFXavier
Created March 28, 2020 18:51
Show Gist options
  • Save ViniciusFXavier/94f33e3283e7f367bc94da01291ddd7b to your computer and use it in GitHub Desktop.
Save ViniciusFXavier/94f33e3283e7f367bc94da01291ddd7b to your computer and use it in GitHub Desktop.
CodeWars - Kata - Stop gninnipS My sdroW!

Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.

Examples:

spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw"
spinWords( "This is a test") => returns "This is a test"
spinWords( "This is another test" )=> returns "This is rehtona test"
import solution = require('./solution');
import {assert} from "chai";
describe("spinWords", function(){
it("should pass a sample test", function() {
assert.strictEqual(solution.Kata.spinWords("Hey fellow warriors"), "Hey wollef sroirraw");
});
});
export class Kata {
static spinWords(words: string) {
return words
.split(" ")
.map(function(word) { return word.length > 4 ? word.split("").reverse().join("") : word })
.join(" ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment