Created
February 18, 2017 23:19
-
-
Save tdlm/7dc1a83178305050a72b7b531c9521c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arrange = (str) => { | |
let words = str.split(' '), i = 0; | |
for (; i < words.length - 1; i++) { | |
if ( | |
(0 === i % 2 && words[i].length > words[i + 1].length) || | |
(1 === i % 2 && words[i].length < words[i + 1].length) | |
) { | |
let tmp = words[i]; | |
words[i] = words[i + 1]; | |
words[i + 1] = tmp; | |
} | |
} | |
return words.map(function(word, i) { | |
return i % 2 == 0 ? word.toLowerCase() : word.toUpperCase(); | |
}).join(' '); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment