Q:

Write a Ruby program to remove last specified characters from a given string

0

Write a Ruby program to remove last specified characters from a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_string(n, my_string)
  n.times do my_string.chop! end
  return my_string
end
print check_string(1, "JavaScript")
print "\n",check_string(2, "JavaScript")
print "\n",check_string(3, "JavaScript")
print "\n",check_string(4, "JavaScript")
print "\n",check_string(5, "JavaScript")

Output:

JavaScrip
JavaScri
JavaScr
JavaSc
JavaS

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now