Write a function that takes a string and returns it with spaces between every letter.
Example:
"october" => "o c t o b e r"
function spaceMaker(str){
return str.split("").join(" ");
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
Test.expect(spaceMaker("october"), "o c t o b e r" );
Test.expect(spaceMaker("space"), "s p a c e" );
Test.expect(spaceMaker("random"), "r a n d o m" );
Test.expect(spaceMaker("javascript"), "j a v a s c r i p t" );
Test.expect(spaceMaker("codewars"), "c o d e w a r s" );
Test.expect(spaceMaker("string"), "s t r i n g" );
An anagram is the result of rearranging the letters of a word to produce a new one.
Write a function that takes a word and returns and array with all anagrams (all possible combinations of letter in a word).
###Example:
allAnagrams("bu") == ["bu", "ub"]
function allAnagrams(word) {
if (word.length < 2) {
return [word];
} else {
var allAnswers = [];
for(var i = 0; i < word.length; i++) {
var letter = word[i];
var shorterWord = word.substr(0, i) + word.substr(i+1, word.length - 1);
var shortWordArray = allAnagrams(shorterWord);
for (var j = 0; j < shortWordArray.length; j++) {
allAnswers.push(letter + shortWordArray[j]);
}
}
return allAnswers;
}
}
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
Test.expect(allAnagrams("bu"), ["bu", "ub"] );
Test.expect(allAnagrams("lol"), ["lol", "llo", "oll", "oll", "llo", "lol"] );
Test.expect(allAnagrams("dog"), ["dog", "dgo", "odg", "ogd", "gdo", "god"] );
Test.expect(allAnagrams("four"), ["four", "foru", "fuor", "furo", "frou", "fruo", "ofur", "ofru", "oufr", "ourf", "orfu", "oruf", "ufor", "ufro", "uofr", "uorf", "urfo", "urof", "rfou", "rfuo", "rofu", "rouf", "rufo", "ruof"] );
Test.expect(allAnagrams("lazy"), ["lazy", "layz", "lzay", "lzya", "lyaz", "lyza", "alzy", "alyz", "azly", "azyl", "aylz", "ayzl", "zlay", "zlya", "zaly", "zayl", "zyla", "zyal", "ylaz", "ylza", "yalz", "yazl", "yzla", "yzal"] )