If you missed the introductory post, it's here. For a list of previously solved katas, please refer to the bottom of this page.
If this is your first time seeing my post, please note - these katas are probably randomly assigned per user so please don't go into Codewars thinking we will have exactly the same user experience, I am just posting these in the order that I got them.
Kata #20
DESCRIPTION:
Complete the solution so that it reverses the string passed into it.
'world' => 'dlrow'
'word' => 'drow'
Starting code:
function solution(str){
}
My attempt (loving the one-liner club!):
const solution = str => str.split('').reverse().join('')
Rank #1 in 'Best Practice':
function solution(str){
return str.split('').reverse().join('');
}
Rank #2:
const solution = str => str.split('').reverse().join('');
Rank #3 with an example of how to use the spread operator:
const solution = s => [...s].reverse().join('')
Rank #4 on how to do it with a for loop:
function solution(s){
var o = '';
for (var i = s.length - 1; i >= 0; i--)
o += s[i];
return o;
}
That's it for Kata #20, stay tuned for more katas to be solved!
Link to Kata #1: Square(n) Sum
Link to Kata #2: Convert a Number to a String
Link to Kata #3: DNA to RNA Conversion
Link to Kata #4: Remove First and Last Character
Link to Kata #5: MakeUpperCase
Link to Kata #6: Total amount of points
Link to Kata #7: A Needle in the Haystack
Link to Kata #8: Sum of positive
Link to Kata #9: Basic Mathematical Operations
Link to Kata #10: Beginner - Reduce but Grow
Link to Kata #11: Square Every Digit
Link to Kata #12: Friend or Foe?
Link to Kata #13: Grasshopper - Summation
Link to Kata #14: Get the Middle Character
Link to Kata #15: Descending Order
Link to Kata #16: String ends with?
Link to Kata #17: Sum of two lowest positive integers