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 123309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:15:58+00:00 2026-05-11T04:15:58+00:00

I came across a javascript puzzle asking: Write a one-line piece of JavaScript code

  • 0

I came across a javascript puzzle asking: Write a one-line piece of JavaScript code that concatenates all strings passed into a function:

      function concatenate(/*any number of strings*/) {       var string = /*your one line here*/       return string;     }   

@ meebo

Seeing that the function arguments are represented as an indexed object MAYBE an array, i thought can be done in a recursive way. However my recursive implementation is throwing an error. –"conc.arguments.shift is not a function" —

      function conc(){         if (conc.arguments.length === 0)              return '';         else              return conc.arguments.shift() + conc(conc.arguments); }  

it seems as though conc.arguments is not an array, but can be accessed by a number index and has a length property??? confusing — please share opinions and other recursive implementations.

Thanks

  • 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. 2026-05-11T04:15:59+00:00Added an answer on May 11, 2026 at 4:15 am

    arguments is said to be an Array-like object. As you already saw you may access its elements by index, but you don’t have all the Array methods at your disposal. Other examples of Array-like objects are HTML collections returned by getElementsByTagName() or getElementsByClassName(). jQuery, if you’ve ever used it, is also an Array-like object. After querying some DOM objects, inspect the resulting jQuery object with Firebug in the DOM tab and you’ll see what I mean.

    Here’s my solution for the Meebo problem:

    function conc(){     if (arguments.length === 0)         return '';     else         return Array.prototype.slice.call(arguments).join(' '); }  alert(conc('a', 'b', 'c')); 

    Array.prototype.slice.call(arguments) is a nice trick to transform our arguments into a veritable Array object. In Firefox Array.slice.call(arguments) would suffice, but it won’t work in IE6 (at least), so the former version is what is usually used. Also, this trick doesn’t work for collection returned by DOM API methods in IE6 (at least); it will throw an Error. By the way, instead of call one could use apply.

    A little explanation about Array-like objects. In JavaScript you may use pretty much anything to name the members of an object, and numbers are not an exception. So you may construct an object that looks like this, which is perfectly valid JavaScript:

    var Foo = {     bar : function() {         alert('I am bar');     },      0 : function() {         alert('I am 1');     },      length : 1 } 

    The above object is an Array-like object for two reasons:

    1. It has members which names are numbers, so they’re like Array indexes
    2. It has a length property, without which you cannot transform the object into a veritable Array with the construct: Array.prototype.slice.call(Foo);

    The arguments object of a Function object is pretty much like the Foo object, only that it has its special purpose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You may have to specify the amount of spaces to… May 11, 2026 at 11:53 pm
  • Editorial Team
    Editorial Team added an answer I got it to work. I was able to get… May 11, 2026 at 11:53 pm
  • Editorial Team
    Editorial Team added an answer I think that the latter option would be easier to… May 11, 2026 at 11:53 pm

Related Questions

I was reading Eloquent JavaScript and I came across this example for the puzzle:
I came across a site that demonstrated a Javascript library and it asked that
While working on a project, I came across a JS-script created by a former
In response to a question about custom fonts, I came across a link to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.