Jump to content

Javascript

Nipplemilk909
Go to solution Solved by myselfolli,
15 hours ago, M.Yurizaki said:

numbers[0];

Well yes, obviously...

looking for a program that takes an input of numbers and returns the min and max value of the set. 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

create a javascript function called findMinMax. This function should take an array of numbers and return an array with two numbers which are the min and max values of the array that was passed in. Log the returned value to the console.Do NOT use the array sort method or any pre-written min and max javascript functions. You also do not need to write your own sort method to solve this problem unless you want too. It can be solved without sorting the array. 

Link to comment
Share on other sites

Link to post
Share on other sites

In what format are the numbers saved? In an array, I'd assume? This is pretty easy to code.

 

There's probably I library for that xD

Link to comment
Share on other sites

Link to post
Share on other sites

What do you mean by you're looking for a program? Are you a coder and are asking for a solution to this? Or do you not know any code and just want a program which achieves that? In which case I'd question why the title is Javascript.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Alir said:

What do you mean by you're looking for a program? Are you a coder and are asking for a solution to this? Or do you not know any code and just want a program which achieves that? In which case I'd question why the title is Javascript.

i just want a program in java that can accomplish this 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Nipplemilk909 said:

i just want a program in java that can accomplish this 

So not Javascript?

 

Javascript and Java are two different languages.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Alir said:

So not Javascript?

 

Javascript and Java are two different languages.

javascript 

Link to comment
Share on other sites

Link to post
Share on other sites

Can I ask what this is for? If you were given this as an assignment as part of a coding course, you would learn more and best to try and accomplish this yourself - it's pretty easy if you have some experience. If you don't, take a free Javascript course online. If you have any specific coding questions, we could answer those. But we won't be of any actual help if we just do it for you. Not that I wouldn't want to answer the simple question and then feel like a boss. But your education is more important than our ego.

Link to comment
Share on other sites

Link to post
Share on other sites

My bad. I just noticed that was you who replied with your requirements for this post and not someone posting an answer.

Link to comment
Share on other sites

Link to post
Share on other sites

I haven't coded JS in months. Just for your effort in not posting a generic request for help, I have given you 'some code' below. DON'T LOOK AT IT IF YOU HAVEN'T EVEN ATTEMPTED THE TASK. I say that for your sake. You won't learn anything that way and it won't be of any benefit to you. If you're completing this task because you need experience with loops, this is a perfect opportunity for you to learn, without looking at the answer

 

https://jsfiddle.net/eq2wxosu/

 

I haven't tested to see if it works. I'll leave that up to you. I have intentionally made mistakes.

 

If you need a decent web development course, check this out:

https://www.udemy.com/the-complete-web-developer-course-2/

 

Udemy often puts their courses on sale at £10. This course is a bargain at that price. You get free website hosting for a year - costs over £100 if you were to pay for it

Link to comment
Share on other sites

Link to post
Share on other sites

And no. I'm not making commission off that link or anything. That course is just actually good!

Link to comment
Share on other sites

Link to post
Share on other sites

function findMinMax(numbers){
  var min = numbers[0];
  var max = numbers[0];
  for (var i = 0; i < numbers.length; i++){
    if (numbers[i] > max){
      max = numbers[i];
    }
    if (numbers[i] < min){
      min = numbers[i];
    }
  }

  return [min, max];
}

There ya go

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, myselfolli said:

function findMinMax(numbers){
  var min = numbers[0];
  var max = numbers[0];
  for (var i = 0; i < numbers.length; i++){
    if (numbers[i] > max){
      max = numbers[i];
    }
    if (numbers[i] < min){
      min = numbers[i];
    }
  }

  return [min, max];
}

There ya go

 

y u du dis

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Alir said:

 

y u du dis

?

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, myselfolli said:

?

lol I was intentionally leaving mistakes so that he/she could debug and figure out the mistakes. Hence learning what was wrong and why. I naturally assumed this was a homework-style assignment so me posting the answer wouldn't have helped him/her learn.

Link to comment
Share on other sites

Link to post
Share on other sites

xD

 

Okay disregard my code, it apparently works too well :P

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, myselfolli said:

xD

 

Okay disregard my code, it apparently works too well :P

Use jQuery. It great for quality bug-free code and does everythings

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Alir said:

Use jQuery. It great for quality bug-free code and does everythings

I know and usually I do, but it was (at least semi-clearly) stated, that we were supposed to use javascript.

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
Share on other sites

Link to post
Share on other sites

In regards to the web dev course, if you're wondering how the guy makes money off of the web hosting if people are getting >£100 hosting for £10, 1) He makes long-term customers and 2) I assume most people end up not even taking advantage of it fully eg. giving up halfway through as is unfortunately the case with a lot of online courses that don't set you deadlines or give you a limited time to complete it in.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, myselfolli said:

I know and usually I do, but it was (at least semi-clearly) stated, that we were supposed to use javascript.

I meant

 

1 hour ago, Alir said:
Image result for javascript jquery joke

 

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, myselfolli said:

xD

is this how i would call it ?

function findMinMax(numbers){
  var min = numbers[0];
  var max = numbers[0];
  for (var i = 0; i < numbers.length; i++){
    if (numbers > max){
      max = numbers;
    }
    if (numbers < min){
      min = numbers;
    }
  }

  return [min, max];
}

findMinMax(3,2,2,4,6,7,78,9,3,21,6)

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Nipplemilk909 said:

is this how i would call it ?

function findMinMax(numbers){
  var min = numbers[0];
  var max = numbers[0];
  for (var i = 0; i < numbers.length; i++){
    if (numbers > max){
      max = numbers;
    }
    if (numbers < min){
      min = numbers;
    }
  }

  return [min, max];
}

findMinMax(3,2,2,4,6,7,78,9,3,21,6)

You need to feed it an array.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×