Well nobody said the list was dynamic so if it’s just defined like that you don’t need to use “code” to find the smallest value, you can just use your eyes.
It's likely that the built-in sort is significantly faster than a linear scan in the high level language. So - this is not only correct, it's probably faster.
A hand crafted machine code sort can be bloody fast compared to a high level language.
And - speed of execution isn't the only speed there is. Speed of development can be very important. Spending an hour writing code you'll use once and takes 1 second to execute is inferior to spending 5 minutes and taking 2 seconds to execute.
This is the interviewer's fuckup for poor requirements. Code performs as requested. Issues from applying the code outside design parameters are a design fault, not a bug. That said, I'd be far more likely to hire this person for QA than development, as their mind clearly appreciates a maze of twisty passages, all likely to cause either race conditions or implicit assumption faults.
Yeah, I had an interview that was basically an off my 1 error, fired up the debugger and talked/walked tough it, fixed it, and they never called me back.
Few things wrong here... (1) JavaScript sorts alphabetically, so this fails with mixed length numbers e.g. [6, 3, 60, 100] => [100, 3, 6, 60] (2) Answer has a poor Big-O and is slow due to sorting (3) Answer could be shorter and more readable `Math.min(...a)`
To sort numerically, you want `myArray.sort((a, b) => a - b)`. Otherwise JS defaults to alphabetically. You need the `(a, b) => a - b` comparison function.
I've seen worse code. Main issue here is my point (1), where the sort won't give you the right answer.
`[ 5, 1000, 4, 9 ].sort()[0]` will return 1000, due to JS .sort() default casting to strings and comparing the UTF-16 codepoint values. > The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
It is SO fucking stupid when they ask you to write code to do something that has literally existed as built in functionality in programming languages for over a quarter century.
This code is not efficient. It's simple, yes, but it's slower than a good solution. The optimal solution is O(n) and this is O(n*log(n)). It also takes more memory.
var a = [4, 2, 6, 9, 4, 2, 5]; var smallest = a[0];
for (var i = 1; i < a.length; i++) { if (a[i] < smallest) { smallest = a[i]; } }
console.log(smallest);
I think that gives better big O complexity. But the meme solution does work and is one of those waste of time coding questions these horrible tech interviews love to use.
Also the meme's answer does not work, except for the given example. JavaScript sorts alphabetically, so this fails with mixed length numbers e.g. [6,3,60,100] => [100, 3, 6, 60].
To sort numerically, you want `myArray.sort((a, b) => a - b)`. Otherwise JS defaults to alphabetically. You need the `(a, b) => a - b` comparison function.
Your answer is actually far superior since theirs will also be wrong with the number 10 or 100 etc in the list since it is alphabetical sort so both will be wrong depending on data input
Your solution - while correct - is likely slower than the built-in sort, surprisingly enough. The system library sort routines in most languages have been heavily optimized for speed - especially for a small list.
It's gonna depend on a few things - your javascript engine, array size, and maybe how random the data is.
I did javascript in the 90's - the built-ins were orders of magnitude faster. That's less true today. The correct answer is to profile the code if speed is an issue.
It always depends, and profiling will need to be done to validate and verify. I do think it's relatively safe to say using built-ins is likely faster -nl not just performance but readability and overall developer experience
Basically that the purpose of the question is to demonstrate that you can recreate the inner workings of the kind of comparison algorithm to perform the work. Instead pre-built functionality of a language is being used to arrive at the end-result that creating it yourself would.
Which is, in itself a dumb as fuck request which leads to people actually thinking they can write better procedures (hint: no they fucking don't)to do things like find and replace and sort. And then Decades later some shmuck like me has to constantly rinse their eyes with eyebleach and get addicted to pain killers because that super find and replace is an goddamn infinite loop in the right circumstances, the right circumstances being someone tried to find and replace...
There are three different skills at play, and unfortunately many only recognize the first two. You need to know what the language and environment can offer built in, and leverage that. You need to know the underlying fundamentals of how basic algorithms work. AND you need to know when to apply each.
Certainly one should avoid reinventing the wheel. But if you don't know the inner workings of 'the wheel' it might never occur to you that the code you are about to write is just a modified wheel.
It's really not. The answer given is terrible as it is slow. There are much better solutions. If a candidate ever gave me this as an answer during an interview, this would be the point where I'd start asking them about what games they've been playing since they're definitely not getting the job.
Few things... (1) JavaScript sorts alphabetically, so this fails with mixed length numbers e.g. [6,3,60,100] => [100, 3, 6, 60] (2) Answer has a poor Big-O and is slow due to sorting (3) Answer could be shorter and more readable `Math.min(...a)`.
I should have also called out: (4) poor test case—negatives, positives, zero, -0, floats, NaN, large numbers, BigInts, int32array, ArrayBuffer, Infinity, non-numbers like null and objects; and not asking the interviewer clarification questions if these matter and what they mean by "number" (5) no input validation (6) sort mutates the input array (7) using `var` instead of `let` or `const`
It's using alphabetical sort, all languages default sort is this exact type of sort. The only real difference here is javascript doesn't tell you that. But honestly I do not know of a language that has a default sort that isn't the same.
Nope. You want `myArray.sort((a, b) => a - b)` to sort numerically. Otherwise JS defaults to alphabetically. You need the `(a, b) => a - b` comparison function.
Is that method better than hard typing the array to int32? I don't deal with JS ever so the lack of typing is weird to me but this guarantees your input is always an integer sort right? var a = new Int32Array([3, 1, 6, 100]); a.sort(); console.log(a[0])
Interviewer asked to find the smallest "number", which you'd have to ask if that means Int32. Otherwise valid numbers in JS include: floats, Infinity, -0, NaN. Plus interviewer may want BigInts. Weird corner cases to handle like is -0 smaller than 0? Should non-numbers be excluded (input validation)?
Your first point is interesting, wasn't aware of that!
Another point is that even if the sorting algo did work, you're only asked to find the lowest value, not sort the list, so rearranging it could fuck up potentially useful data since we aren't given the context for the variable.
(2) is not necessarily a poor Big-O. most implementation of Array.sort is merge/insertion sort which is O(n log n). But also proven to be a good compromise on speed/memory for real world data
You can do in O(N) by checking if each element is the new lowest seen value. Any comparison-sort also needs to do at least N comparisons (generally far more). You'll want to stick to built-in functions, like `Math.min.apply(null, array)`.
generally speaking, this is correct. Too many coders try to be overly clever. However, leaning on existing functions like min() allows your code to benefit from future framework efficiency gains.
You forgot to return just the lowest value, to fully answer the interview question. Also, thank you for your time. You can head home now; you can skip the rest of the interviews. We'll be in touch.
I understand what that does, but what language is this? variable a is the list for each element in a (set a timeout equal to that element (print the element to the screen) after the timeout)
Thank you! I had never seen this before, but it got me thinking. I whipped it together in Java as a multithreaded example using sleep and I'm going to present it to my students along with some discussion questions like: What's the time complexity? In practice, what factor dominates the runtime? Is this a joke, if so, why? Are there circumstances under which this would be a good sorting algorithm? And so on, so genuinely THANK YOU, I think this makes a great learning example.
The best sorting algorithm is Stalin Sort and has a run time of O(n). It states that for each element in the list, if such element is not already sorted, it is eliminated from the list.
I think it would actually be O(n^2). If you sleep for 1s times the value of each item, it will break if it takes more than one second to assign all those timeout callbacks, [2,3,4,1] might return 2,1,3,4 if the last callback is set a second after the first. Iterating the list that way is O(n), which is the lower bound for how long to sleep, so the overall algo is O(n^2). It's just hidden because the test cases are so tiny, that it acts more like O(n) with a huge K.
There's also the oddity that it scales based on the values. Sorting [4,3,2,1] takes much less time than sorting [104,103,102,101]. Big-O notation doesn't cover that.
well.. it won't if the numbers are too close together and there are too many of them. It depends more and more on your actual computer hardware and the order of them being set into the sleep at that point lmao. Mystery outcome sort
It tells the computer to wait x time them print x. So you give it 5, 1, 10. In 1 second, it prints 1, in 5 seconds it prints 5, and in 10 seconds, it prints 10. What you see on the console is 1, 5, 10.
I know it will work, but setting the timeout at 500 is half a second so it might be noticeable then. If your system can run the code and update the screen in less than a millisecond, then it will be start to be noticeable at some point, maybe not exactly at 500, but at some point, yes
TimeFoDat
Well nobody said the list was dynamic so if it’s just defined like that you don’t need to use “code” to find the smallest value, you can just use your eyes.
fformulaa
khalwat
Even easier is: console.log(Math.min(...a));
Vengeraxe
DavidBrooker
"Our first step is to re-define the concept of counting from first principles starting with the definition of the set" - Cantor, probably
LoftheDesert
But what if the code should sort it according to user input and not a predetermined list.
Hekatombe
Jitter, take the wheel!
Sorrontis
not wrong though.
HzZbVYAx77aoiuN9Zy
Yes it is, it's doing an alphabetical sort. It is only correct if the data input is correct, otherwise 10, 100, 1000 etc will come before 2
Skuggen
If you're the one writing the list, why not just make it sorted to begin with?
plinkey
That takes 4 years of college, and usually a graduate degree to learn to type: "ORDER BY"
evilspock
It's likely that the built-in sort is significantly faster than a linear scan in the high level language. So - this is not only correct, it's probably faster.
comacomacomacomachameleon
if you discover a sorting algorithm that is provably better than O(n), you will win a Nobel Prize.
evilspock
But it's not just algorithm, it;s implementation.
A hand crafted machine code sort can be bloody fast compared to a high level language.
And - speed of execution isn't the only speed there is. Speed of development can be very important. Spending an hour writing code you'll use once and takes 1 second to execute is inferior to spending 5 minutes and taking 2 seconds to execute.
HzZbVYAx77aoiuN9Zy
It's not only wrong though
evilspock
It works for the given dataset, but yes - you'd want to make that a numeric sort.
kin24atrheg676755667gfdfd
Queeeeeeeeeeeeeeeeeeee
phobosorbust
This is the interviewer's fuckup for poor requirements. Code performs as requested. Issues from applying the code outside design parameters are a design fault, not a bug.
That said, I'd be far more likely to hire this person for QA than development, as their mind clearly appreciates a maze of twisty passages, all likely to cause either race conditions or implicit assumption faults.
plinkey
Yeah, I had an interview that was basically an off my 1 error, fired up the debugger and talked/walked tough it, fixed it, and they never called me back.
phobosorbust
I'd be tempted to send them a bill for my consulting fee.
They might even pay it without realizing what it was for.
RummageSaleBubbler
Few things wrong here...
(1) JavaScript sorts alphabetically, so this fails with mixed length numbers e.g. [6, 3, 60, 100] => [100, 3, 6, 60]
(2) Answer has a poor Big-O and is slow due to sorting
(3) Answer could be shorter and more readable `Math.min(...a)`
RummageSaleBubbler
To sort numerically, you want `myArray.sort((a, b) => a - b)`. Otherwise JS defaults to alphabetically. You need the `(a, b) => a - b` comparison function.
> The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Jarjarthejedi
Yeah, Math.min() is definitely the better answer here. Why bother sorting the whole list?
RummageSaleBubbler
I've seen worse code. Main issue here is my point (1), where the sort won't give you the right answer.
`[ 5, 1000, 4, 9 ].sort()[0]` will return 1000, due to JS .sort() default casting to strings and comparing the UTF-16 codepoint values.
> The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
HisRoyalMajestyKingV
It is SO fucking stupid when they ask you to write code to do something that has literally existed as built in functionality in programming languages for over a quarter century.
plinkey
KerryCoder
```
var a = [6, 2, 3, 8, 1, 4];
console.log(Math.min(...a));
```
ComicSansHumor
This code is not efficient. It's simple, yes, but it's slower than a good solution. The optimal solution is O(n) and this is O(n*log(n)). It also takes more memory.
plinkey
shut up nerd
ComicSansHumor
crodrigues
I know a lot of you will hate this
var a = [6,2,3,8,1,4];
console.log(a[a.reduce((x, y) => x + y, 0) / a.length]);
KerryCoder
NussKnuspermix
In case someomes wondering, a real solution isn't that much longer. For example:
Var a = [6, 2, 3, 8, 1, 4], m = a[0], i = 1;
while (i < a.length) if (a[i] < m) m = a[i]; i++;
console.log(m);
I'm sure there's a more efficient way but this should get the job done pretty straight forward no overhead.
plinkey
x.Where(entry => entry.Value => min);
Tumescentpie
var a = [4, 2, 6, 9, 4, 2, 5];
var smallest = a[0];
for (var i = 1; i < a.length; i++) {
if (a[i] < smallest) {
smallest = a[i];
}
}
console.log(smallest);
I think that gives better big O complexity. But the meme solution does work and is one of those waste of time coding questions these horrible tech interviews love to use.
HzZbVYAx77aoiuN9Zy
put the number 10 or 100 in that list and you will see it does not work ;p
RummageSaleBubbler
Math.min(...a)
RummageSaleBubbler
Also the meme's answer does not work, except for the given example. JavaScript sorts alphabetically, so this fails with mixed length numbers e.g. [6,3,60,100] => [100, 3, 6, 60].
[deleted]
[deleted]
RummageSaleBubbler
Nope. Try my example above. Default is casting to a string then comparing the UTF-16 codepoints.
RummageSaleBubbler
To sort numerically, you want `myArray.sort((a, b) => a - b)`. Otherwise JS defaults to alphabetically. You need the `(a, b) => a - b` comparison function.
> The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Relayu
Smallest = a[1] is quicker, but may give the wrong answer occasionally
HzZbVYAx77aoiuN9Zy
Your answer is actually far superior since theirs will also be wrong with the number 10 or 100 etc in the list since it is alphabetical sort
so both will be wrong depending on data input
evilspock
Your solution - while correct - is likely slower than the built-in sort, surprisingly enough. The system library sort routines in most languages have been heavily optimized for speed - especially for a small list.
Xendrash
For large arrays (~1 million elements), sorting will generally be slower than a simple loop because of the O(n log n) complexity.
c0i9z
The built-in solution can't possibly be faster than looking at each element in a list and doing one comparison for each of them.
pnersvfu
It can if the under lying sort calls into fast as fuck machine code rather that interpreted code
evilspock
It's gonna depend on a few things - your javascript engine, array size, and maybe how random the data is.
I did javascript in the 90's - the built-ins were orders of magnitude faster. That's less true today. The correct answer is to profile the code if speed is an issue.
pnersvfu
It always depends, and profiling will need to be done to validate and verify. I do think it's relatively safe to say using built-ins is likely faster -nl not just performance but readability and overall developer experience
L4t3xs
A lot of students just had their first lesson in programming, huh?
plinkey
I'm just here trying to teach em. stop thinking you're clever, you're not.
RhinoNaut
They wanted code not math. This is what they asked for.
EveryUsernameIsTaken4
What's the joke here?
quzar
Basically that the purpose of the question is to demonstrate that you can recreate the inner workings of the kind of comparison algorithm to perform the work. Instead pre-built functionality of a language is being used to arrive at the end-result that creating it yourself would.
MelodyLightfoot
Which is, in itself a dumb as fuck request which leads to people actually thinking they can write better procedures (hint: no they fucking don't)to do things like find and replace and sort. And then Decades later some shmuck like me has to constantly rinse their eyes with eyebleach and get addicted to pain killers because that super find and replace is an goddamn infinite loop in the right circumstances, the right circumstances being someone tried to find and replace...
quzar
There are three different skills at play, and unfortunately many only recognize the first two. You need to know what the language and environment can offer built in, and leverage that. You need to know the underlying fundamentals of how basic algorithms work. AND you need to know when to apply each.
Certainly one should avoid reinventing the wheel. But if you don't know the inner workings of 'the wheel' it might never occur to you that the code you are about to write is just a modified wheel.
ManOfSamos
Coding equivalent of being asked ‘Write a formula where x equals 3’ and answering ‘x = 3’
lospaturno
worse, it's like "find X" and drawing an arrow instead of making calculations
ddbrown30
It's really not. The answer given is terrible as it is slow. There are much better solutions. If a candidate ever gave me this as an answer during an interview, this would be the point where I'd start asking them about what games they've been playing since they're definitely not getting the job.
RummageSaleBubbler
Few things...
(1) JavaScript sorts alphabetically, so this fails with mixed length numbers e.g. [6,3,60,100] => [100, 3, 6, 60]
(2) Answer has a poor Big-O and is slow due to sorting
(3) Answer could be shorter and more readable `Math.min(...a)`.
RummageSaleBubbler
I should have also called out:
(4) poor test case—negatives, positives, zero, -0, floats, NaN, large numbers, BigInts, int32array, ArrayBuffer, Infinity, non-numbers like null and objects; and not asking the interviewer clarification questions if these matter and what they mean by "number"
(5) no input validation
(6) sort mutates the input array
(7) using `var` instead of `let` or `const`
ChernoGamma
Big O you say?
theirongiant74
.sort() sorts alphabetically by default, you can pass in your own evaluation function to make it sort in whatever manner you please
HzZbVYAx77aoiuN9Zy
You are correct, these people jumping to conclusions instead of taking literally 5 seconds to test it. I did it for them
Trelis
Still found the smallest number.
RummageSaleBubbler
tldr; I'm right, but unconvincing.
HzZbVYAx77aoiuN9Zy
picture speaks 1000 words! however your post went from -5 to 0 now so there is still hope
Doopapotamus
Thank you for the breakdown!
AntiProtonBoy
No, JS interprets these as numbers. Alphabetical sort is only in effect when you put the numbers within quotation marks.
Jarjarthejedi
Sadly no. JS is a...well, it's a language. Try it yourself https://playcode.io/javascript "var a = [6,3,60,100];a.sort();console.log(a)"
HzZbVYAx77aoiuN9Zy
you expect too much, no it doesn't
justfillingthespace
That's so unimaginably shitty that I can't even begin to articulate how much I hate it. I never want to see this again.
AntiProtonBoy
holy fuck, what a clusterfuck of a language
HzZbVYAx77aoiuN9Zy
It's using alphabetical sort, all languages default sort is this exact type of sort. The only real difference here is javascript doesn't tell you that. But honestly I do not know of a language that has a default sort that isn't the same.
RummageSaleBubbler
Nope. You want `myArray.sort((a, b) => a - b)` to sort numerically. Otherwise JS defaults to alphabetically. You need the `(a, b) => a - b` comparison function.
> The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Snaitf
Tested and confirmed:
imredheaded
Is that method better than hard typing the array to int32? I don't deal with JS ever so the lack of typing is weird to me but this guarantees your input is always an integer sort right?
var a = new Int32Array([3, 1, 6, 100]);
a.sort();
console.log(a[0])
RummageSaleBubbler
Interviewer asked to find the smallest "number", which you'd have to ask if that means Int32. Otherwise valid numbers in JS include: floats, Infinity, -0, NaN. Plus interviewer may want BigInts. Weird corner cases to handle like is -0 smaller than 0? Should non-numbers be excluded (input validation)?
DoorTable
Your first point is interesting, wasn't aware of that!
Another point is that even if the sorting algo did work, you're only asked to find the lowest value, not sort the list, so rearranging it could fuck up potentially useful data since we aren't given the context for the variable.
OriginalSyn
(2) is not necessarily a poor Big-O. most implementation of Array.sort is merge/insertion sort which is O(n log n). But also proven to be a good compromise on speed/memory for real world data
RummageSaleBubbler
You can do in O(N) by checking if each element is the new lowest seen value. Any comparison-sort also needs to do at least N comparisons (generally far more). You'll want to stick to built-in functions, like `Math.min.apply(null, array)`.
FartsSmellBad
print(min(a))
KerryCoder
Right answer, wrong language.
RummageSaleBubbler
Math.min(...a)
HzZbVYAx77aoiuN9Zy
Uncaught ReferenceError: min is not defined
imNotThisCleverIRL
generally speaking, this is correct. Too many coders try to be overly clever. However, leaning on existing functions like min() allows your code to benefit from future framework efficiency gains.
FartsSmellBad
I do SQL more than anything, and I am just floored at some of the complexity people put together with usually much simpler solutions
Eyhlix
floor(FartsSmellBad) /s
lospaturno
"an exception occurred" (another programmer overloaded min() )
Jarjarthejedi
"You guys are working in a language that allows overloading min()? Why is your company 30 years behind the curve?"
plinkey
python
Jarjarthejedi
Since when does python allow overloading built-in functions? That wasn't an option the last time I worked on it a few years back.
plinkey
since always, python is dumb, but good for some things.
lospaturno
Wor3q
My favourite so far was a way to sort a list: a.forEach(el => setTimeout(() => console.log(el), el) )
ChareAndFlaff
pipatron
I tried with signed number and to my surprise, I got the answer even before I ran the code!
TheOldHen
I was feeling down after seeing some bad code today. This made me feel better.
Foxsayy
.
RummageSaleBubbler
You forgot to return just the lowest value, to fully answer the interview question. Also, thank you for your time. You can head home now; you can skip the rest of the interviews. We'll be in touch.
DidItForScience
I understand what that does, but what language is this?
variable a is the list
for each element in a (set a timeout equal to that element (print the element to the screen) after the timeout)
ZiomalZParafii
JavaScript
plinkey
I need to use this somewhere...
foozlewastaken
you can even add some complexity to it to help you actually capture the lowest value
function least(list) {
return Promise.race(list.map((e) => new Promise((resolve) => setTimeout(resolve, e, e))));
}
ChareAndFlaff
Thank you! I had never seen this before, but it got me thinking. I whipped it together in Java as a multithreaded example using sleep and I'm going to present it to my students along with some discussion questions like: What's the time complexity? In practice, what factor dominates the runtime? Is this a joke, if so, why? Are there circumstances under which this would be a good sorting algorithm? And so on, so genuinely THANK YOU, I think this makes a great learning example.
remindmetostopprocrastinating
Wow. Impressively creative
regnulify
Should have sent a poet!
SLCtechie
The best sorting algorithm is Stalin Sort and has a run time of O(n). It states that for each element in the list, if such element is not already sorted, it is eliminated from the list.
plinkey
but i neeeded the 2 datastruct...?
Wraid
Hekatombe
Sleep sort. One of the easiest sorting algorithms out there.
soulsource
And one that scales O(n). Take that, "quick"sort.
japh
You're assuming the thread scheduler operates in constant time.
lospaturno
I always asked myself.. still O(n) if you start N processes and count X times, with X the number? isn't it a nested for cycle? or sleeping is O(1)?
conMan76
gman003
I think it would actually be O(n^2). If you sleep for 1s times the value of each item, it will break if it takes more than one second to assign all those timeout callbacks, [2,3,4,1] might return 2,1,3,4 if the last callback is set a second after the first. Iterating the list that way is O(n), which is the lower bound for how long to sleep, so the overall algo is O(n^2). It's just hidden because the test cases are so tiny, that it acts more like O(n) with a huge K.
gman003
There's also the oddity that it scales based on the values. Sorting [4,3,2,1] takes much less time than sorting [104,103,102,101]. Big-O notation doesn't cover that.
onlyhalfghost
the order is linear n, it's just a very high unit of n
06cpayne
Wait WHY DOES THIS WORK
HzZbVYAx77aoiuN9Zy
well.. it won't if the numbers are too close together and there are too many of them. It depends more and more on your actual computer hardware and the order of them being set into the sleep at that point lmao. Mystery outcome sort
Columbus43219
It tells the computer to wait x time them print x. So you give it 5, 1, 10. In 1 second, it prints 1, in 5 seconds it prints 5, and in 10 seconds, it prints 10. What you see on the console is 1, 5, 10.
SkamanSam
Yes, but in this case it's milliseconds so you probably wouldn't even notice unless the numbers go past 500
Columbus43219
foozlewastaken
Nah it works, as it'll be queued to the call stack in the order from smallest to largest timeout
https://imgur.com/BKVn1DB
SkamanSam
I know it will work, but setting the timeout at 500 is half a second so it might be noticeable then. If your system can run the code and update the screen in less than a millisecond, then it will be start to be noticeable at some point, maybe not exactly at 500, but at some point, yes
06cpayne
OH COME ON
plinkey
if someone did this in an interview, i'd give them a stern talking to about how javascript is horrible and then probably recommend hiring them.
06cpayne
I just figured it out and wow.