arrays - Basic JavaScript Sort Above Mean and Below -


I am trying to write a JavaScript code that will take input from users and find meaning. Then it should be placed in a list above the numbers and numbers below the mean. Everything is working down except that sorting the numbers below and above the average. To help you,

  function getNums () {var nums = new Array (); Var numAmt = prompt ("How many data values ​​do you have?"); NumAmt = parseInt (numAmt); Var i = 0; For (i = 0; i & lt; = numAmt - 1; i ++) {nums [i] = Prompt ("Enter data value number" + (i + 1)); } Var sum = 0; (I = 0; i  average) big = = parseInt (number [i]); And small + = parseint (number [i]); Document.getElementById ('number'). InnerHTML = "Your data:" + nums; Document.getElementById ('Avg.'). InnerHTML = "The average (average) of these numbers is:" + avg.toFixed (2) + ".. & Lt; br & gt;"); Document.getElementById ('Big'). InnerHTML = "Your data:" + Big; Document.getElementById ('Short'). InnerHTML = "Your data:" + Small; }}   

I will personally break it into two tasks, focusing on one " This array means ", and the second" Sort this array around a pivot "

  function mean (ARR) {var sum = arr.reduce (function (previous, curr) {return prev + curu;}); Return amount / arr.length; } Function pivotSort (arr, smoke) {var sorted = []; Arr.forEach (function (val) {if (val> gt; pivot) sorted.push (val); else sort.unshift (val);}); }  

Pivot sort is also not closed to optimize, but HEC, V8 is very fast nowadays.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -