Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:49:43+00:00 2026-06-16T06:49:43+00:00

I’m interested in possible ways that different languages can Join an array, but rather

  • 0

I’m interested in possible ways that different languages can Join an array, but rather than using a single join string, using a different join string at given intervals.

For example (hypothetical language):

Array.modJoin([mod, char], ...)
e.g. [1,2,3,4,5].modJoin( [1, ","], [2, ":"] )

Where the arguments specify an array or object containing a modulo and a join char, the implementation would check which order of modulo took precedence (the latest one), and apply the join char. (requiring that the [mod,char]’s were provided in ascending mod order)

i.e.

if (index % (nth mod) == 0) 
  append (join char) 
  continue to next index 
else 
  (nth mod)-- repeat

when complete join with ""

For example, I’ve come up with the following in Ruby, but I suspect better / more elegant methods exist, and that’s what I’d like to see.

#Create test Array 
#9472 - 9727 as HTML Entities (unicode box chars)
range       = (9472..9727).to_a.map{|u| "&##{u};" }  

Assuming we have a list of mod’s and join chars, we have to stipulate that mods increase in value as the list progresses.

mod_joins   = [{m:1, c:",", m:12, c:"<br/>"]

Now process the range with mod_joins

processed = range.each_with_index.map { |e, i| 
  m = nil
  mods.reverse_each {|j|
    m = j and break if i % j[:m] == 0
  }
  # use the lowest mod for index 0
  m = mods[0] if i == 0 
  m = nil ? e : "#{e}#{m[:c]}"
}

#output the result string
puts processed.join ""

From this we have a list of htmlEntities, separated by , unless it’s index is a 12th modulo in which case it’s a <br/>

So, I’m interested for ways this can be done more elegantly, primarily in functional languages like Haskell, F#, Common Lisp (Scheme, Clojure) etc. but also cool ways to achieve this in general purpose languages that have list comprehension extensions such as C# with Linq, Ruby and Python or even Perl.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:49:46+00:00Added an answer on June 16, 2026 at 6:49 am

    Here’s a simpler and more readable solution in Ruby

    array = (9472..9727).map{|u|"&##{u};"}
    array.each_slice(12).collect{|each|each.join(",")}.join("<br/>")
    

    or for the general case

    module Enumerable   
      def fancy_join(instructions)
        return self.join if instructions.empty?
        separator = instructions.delete(mod = instructions.keys.max)
        self.each_slice(mod).collect{|each|each.fancy_join(instructions.dup)}.join(separator)
      end
    end
    
    range = (9472..9727).map{|u|"&##{u};"}
    instructions = {1=>",",12=>"<br/>"}
    
    puts array.fancy_join(instructions)    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.