7  Reversed Strings

Tantangan #7/366 - 21 Feb 2024

https://www.codewars.com/kata/5168bb5dfe9a00b126000018

8kyu Reversed Strings

7.1 Instruction

Complete the solution so that it reverses the string passed into it.

'world'  =>  'dlrow'
'word'   =>  'drow'

7.2 YouTube Video

7.3 Solution Code

Solusi bar-bar

solution <- function(s){
  str_split <- unlist(strsplit(s, ""))
}

Solusi simple

solution <- function(s){
  paste(rev(unlist(strsplit(s, ""))), collapse = "")
}

7.4 Test

library(testthat)

test_that("example", {
  expect_equal(solution('world'), 'dlrow')
  expect_equal(solution('hello'), 'olleh')
  expect_equal(solution(''), '')
  expect_equal(solution('h'), 'h')
})
Test passed 🎉

7.5 Supported by

StarCore Analytics