Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sick to complete this code

    hi there.

    anyone can help me to complete this

    3. The following Javascript function, while grammatically correct, is sometimes unreliable. It is to be deprecated and you have been tasked to create a new function. It should accept an array parameter and assign each element in the array value to the supplied input value. If input array is a multi dimensional array it should reset the children elements as well.

    function myresetter_func (counter, arr1, str)
    {
    i = q = counter = 0;
    temp = arr1;

    for (var i=0;i<temp.length;i++){
    if(temp[i].length > 0)
    {
    for (q=0;q<temp[i].length;q++)
    {
    temp[i][q] = str;
    }
    } else
    temp[i] = str;
    }
    return temp;
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Show the code that you have written so far.

    As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.

    It is recommended that you place the opening brace following the function, if, else, for, while, do, switch, and try statements on the same line and not on the following line. Apart from that every Javascript statement should be followed by a semi-colon (;). It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage.
    Last edited by Philip M; 01-17-2013 at 12:58 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Additionally you should want to do it on your own rather than have someone else do it. Because if you don't give a damn about learning this, drop whatever you're doing and pick another career, something you're willing to learn.

    The IT business has already more than enough retards who somehow cheated their way through college to get a good job. I deal with them every day.

    air

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I sure hope this is just a wrong translation from the original language into English:
    assign each element in the array value to the supplied input value.
    That would say "none of the array element values are changed; instead they are assigned one at a time to the input variable [which doesn't exist, but that's another problem] ." The result of course would be that input would contain the value of the last array element found. But since the problem doesn't specify the *order* in which the array elements are to be traversed, that means you could assign the value of any array element to input and be correct.

    Clearly the sentence SHOULD read:
    assign the value of the argument named str to each element of the array argument named arr1
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •