9  Convert a Number to a String!

8kyu Tantangan #9/366 - 23 Feb 2024

https://www.codewars.com/kata/5265326f5fda8eb1160004c8

9.1 Instruction

We need a function that can transform a number (integer) into a string.

What ways of achieving this do you know?

Examples (input –> output):

123  --> "123"
999  --> "999"
-100 --> "-100"

9.2 YouTube Video

9.3 Solution Code

number_to_string <- function(n) {
  as.character(n)
}
number_to_string <- as.character

9.4 Test

library(testthat)

test_that("fixed tests", {
  expect_equal(number_to_string(67), '67')
  expect_equal(number_to_string(79585), '79585')
  expect_equal(number_to_string(3), '3')
  expect_equal(number_to_string(-1), '-1')
})
Test passed 🥇

9.5 Supported by

StarCore Analytics