0

So I believe the title says it all. Does anybody know why? Also, the decimal point doesnt visibly appear, but the code acts like it is there.

PS: Please don't try and fix my code in a way that doesn't help me fix this, I find it annoying

let n = [
  1, 2, 3, 4, 5
]
let i = 0
let it = 0
let l = 1000 ^ 100
let p = 0
let sort = true
let f = 0
let g = n.length
let h = 0
document.getElementById('button').addEventListener("click", function() {
  stuff()
})

function stuff() {
  if (n[0] <= n[1] && n[1] <= n[2] && n[2] <= n[3] && n[3] <= n[4]) {
    n[0] = document.getElementById("a").value
    n[1] = document.getElementById("b").value
    n[2] = document.getElementById("c").value
    n[3] = document.getElementById("d").value
    n[4] = document.getElementById("e").value
    it = 0
    i = 0
    l = 1000 ^ 100
    p = 0
    sort = true
    f = 0
    g = 0
    h = 0
  }
  console.log("in function 1")
  lowestSort(n)
}

function lowestSort(n) {
  console.log("in function 2")
  sort = true
  while (g <= n.length && sort == true) {
    console.log("in while loop")
    if (n[i] > n[g] && g >= f) {
      [n[i], n[g]] = [n[g], n[i]]
      console.log(g)
      sort = false
    } else {
      f = i + 1
      console.log("f =", f)
    }
    g += 1
  }
  g = 0
  i += 1
  it += 1
  if (i == 4) {
    i = 0
  }
  document.getElementById("f").innerHTML = n
  document.getElementById("g").innerHTML = it
}
<h1>superSort Algorithm</h1><a href=".\dubble.html">(Psst: Click me for dubble sort!)</a><br><a href=".\bubble.html">(Psst: Click me for bubble sort!)</a>
<p>Enter your number. superSort checks to see if any number is less then the one its on, and if so switches them, and if not it freezes it.</p><br>
<title>superSort</title>

<input type=number id="a"></input>
<br>
<input type=number id="b"></input>
<br>
<input type=number id="c"></input>
<br>
<input type=number id="d"></input>
<br>
<input type=number id="e"></input>
<br><br><button id="button">Press me to run 1 itteration</button>
<p>Output: <span id="f">N/A</span></p>
<p>Iterations: <span id="g">N/A</span></p>

Sorry that it is a bit long, I don't want to leave it at just the JS and make you do the work to put make it work. Thank you in advance. I have tried seeing if I have the same issues in some similar files and I do, so it might be in the stuff() function.

  • Where does a decimal point appear? What is the actual problem? What’s the purpose of `l = 1000 ^ 100`? Did you mean to do a lexicographic sort instead of a numeric one? `` suggests numeric, but you’re comparing the `value` instead of the `valueAsNumber`, which results in a lexicographic sort. Why do you write `` which doesn’t exist? [Edit] to clarify. – Sebastian Simon Mar 14 '22 at 23:37
  • @SebastianSimon I needed a big number, thats the point of `l = 1000^100`, also if someone enters text it would screw over my code, and `` prevents text. Also the decimal point doesnt appear, but through testing (Input numbers being 60, 400, 401, 1, 1) Its answer is [1,1,400,401,60] – Local_Idiot Mar 14 '22 at 23:54
  • You never use `l`. Is 908 really a “big number”? Yes, `` prevents non-numeric inputs, but you’re _not using_ the actual numbers. See [Input value is a string instead of a number](/a/27850041/4642212), and [Bitwise XOR (`^`)](//developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR) and [Exponentiation (`**`)](//developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Exponentiation). `1000 ** 100` is `1e+300` which isn’t a useful number in most circumstances; either consider `Infinity` or clarify what you need this number for. – Sebastian Simon Mar 14 '22 at 23:59
  • _“Also the decimal point doesn’t appear”_ — Then what does your title mean? The answer `[ "1", "1", "400", "401", "60" ]` is a correct lexicographic sort, as I said, because you’re not comparing numbers, so it’s not sorting numerically. – Sebastian Simon Mar 15 '22 at 00:01
  • @SebastianSimon Try and do a different think like (3, 2, 1, 4, 5) – Local_Idiot Mar 15 '22 at 00:19
  • Why? What does “(3, 2, 1, 4, 5)” demonstrate? – Sebastian Simon Mar 15 '22 at 00:36

0 Answers0