constpiggy=(str)=>str.split(" ").map(word=>word[0].match(/\w/)?word.slice(1)+word[0]+'ay':word).join(" ");console.info(piggy("Pig latin is cool"));console.info(piggy("Hello world !"));
constesrever=(word)=>word.split("").reverse().join("");constspinWords=(str)=>str.split(" ").map(word=>word.length>4?esrever(word):word).join(" ");console.info(spinWords("Hey fellow warriors"));console.info(spinWords("This is a test"));console.info(spinWords("This is another test"));
Nice exercise, this also shows how clumsy JS is when dealing with string data. Everything has to be converted to and from arrays. And these exercises do not work with non-BMP Unicode characters, but that was not in the requirement ;)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Day 1
Time: O(n), Space: O(n)
Day 2
Time: O(n), Space: O(n)
Day 3
Time: O(n), Space: O(n)
Day 4
Time: O(n), Space: O(1)
Nice exercise, this also shows how clumsy JS is when dealing with string data. Everything has to be converted to and from arrays. And these exercises do not work with non-BMP Unicode characters, but that was not in the requirement ;)