+ 3

Help me to find largest and smallest number from array!

largest and smallest number logic

6th Aug 2018, 3:17 AM
Tarika
Tarika - avatar
18 Respostas
+ 3
The logic is simple: We made two variables and set their values to 0(in my case to the first member of the array). Then used a for loop to loop through the array. (I commented most of this in code btw) if there is a number greater or less than the value stored in our variables then that value is saved as the new value of the variable. What's the other help you need?
6th Aug 2018, 6:59 AM
Akib
Akib - avatar
+ 6
You might like: https://www.sololearn.com/learn/774/?ref=app If you just want to find lowest and highest.. let arr = [ 14, 17, 11,8, 3,2,88]; let biggest = arr[0]; let smallest = arr[0]; for(i = 0; i < arr.length ; i++){ if(arr[i] >= biggest){ biggest = arr[i]; } if(arr[i] <= smallest){ smallest = arr[i]; } }
6th Aug 2018, 3:22 AM
Akib
Akib - avatar
+ 4
It seems you finished all the courses how could you not know this?!!!??😱 Anyway - here is the JS code https://code.sololearn.com/W9V4a6GG74iq/?ref=app
6th Aug 2018, 3:35 AM
Akib
Akib - avatar
+ 1
Think about it(second problem) yourself. Take your time. Understand the logic first then try to code.
6th Aug 2018, 7:06 AM
Akib
Akib - avatar
+ 1
ok thank you Akib Reza
6th Aug 2018, 7:11 AM
Tarika
Tarika - avatar
+ 1
To add to Jays idea: Check the index of the largest and smallest number and set them to NULL I guess. I don't know of any function.
6th Aug 2018, 2:06 PM
Akib
Akib - avatar
+ 1
Akib Reza do you know any function for retrieving the index of an array element?
6th Aug 2018, 2:10 PM
Tarika
Tarika - avatar
+ 1
Akib Reza yes sir! ☺
6th Aug 2018, 3:18 PM
Tarika
Tarika - avatar
+ 1
thank u so much Jay Matthews
7th Aug 2018, 2:08 AM
Tarika
Tarika - avatar
+ 1
int high=0,low=arr[0]; for(int i=0;i<arr.length;i++) { if (arr[i]<low) low=arr[i]; else high=arr[i]; } System.out.println("highest and lowest number are:"+ high +" and " + low);
7th Aug 2018, 3:11 PM
deep [Java / JS]
deep [Java / JS] - avatar
0
Akib Reza thank you, but I didn't understanding anything ☺
6th Aug 2018, 3:24 AM
Tarika
Tarika - avatar
0
😶😲...Which language do you know?
6th Aug 2018, 3:33 AM
Akib
Akib - avatar
0
Akib Reza dude, I did not understand the logic
6th Aug 2018, 6:50 AM
Tarika
Tarika - avatar
0
Akib Reza BTW, thanx I need one more Help!!!
6th Aug 2018, 6:54 AM
Tarika
Tarika - avatar
0
i want to find second largest and second smallest number
6th Aug 2018, 7:01 AM
Tarika
Tarika - avatar
0
Jay Matthews is there any method to remove from array?
6th Aug 2018, 11:09 AM
Tarika
Tarika - avatar
0
😐 make one.
6th Aug 2018, 3:06 PM
Akib
Akib - avatar
0
Jay Matthews I am 💔. Why python why...
7th Aug 2018, 1:28 AM
Akib
Akib - avatar