Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerRank Ruby – Strings – Methods I problem solution

YASH PAL, 31 July 2024

In this HackerRank Ruby – Strings – Methods I problem solution In this challenge, your task is to code a process_text method, which takes an array of strings as input and returns a single joined string with all flanking whitespace and new lines removed. Each string has to be separated by a single space.

> process_text([“Hi, n”, ” Are you having fun?    “])

“Hi, Are you having fun?”

HackerRank Ruby - Strings - Methods problem solution

Problem solution.

# Enter your code here. Read input from STDIN. Print output to STDOUT

def process_text arr
    clean_arr = []
    arr.each do | l |
      l = l.chomp
      l = l.strip
      clean_arr << l
    end
    clean_arr.join( " " )
end

Second solution.

# Enter your code here. Read input from STDIN. Print output to STDOUT
def process_text(arr)
    new_arr = arr.map { |x| x.strip }.join(" ")
end

Third solution.

# Enter your code here. Read input from STDIN. Print output to STDOUT

def process_text(arr = [])
    arr.map(&:chomp).map(&:strip).join(' ')
end

coding problems solutions Ruby Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes