forked from IceCreamYou/UnStockMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
34 lines (27 loc) · 805 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$(document).ready(function() {
var submitButton = null;
$('#controls').submit(function(e) {
e.preventDefault();
}).on('keyup mouseup', function(e) {
submitButton = e.target.name;
});
});
// STOCKS ---------------------------------------------------------------------
var stock = function() {
this.amount = 0;
this.value = 10;
this.pastValues = [];
}
// UTILITIES ------------------------------------------------------------------
function getRandBetween(lo, hi) {
return parseInt(Math.floor(Math.random()*(hi-lo+1))+lo);
}
Array.prototype.remove = function(item) {
var i = $.inArray(item, this);
if (i === undefined || i < 0) return undefined;
return this.splice(i, 1);
};
Array.prototype.getRandomElement = function() {
var i = getRandBetween(0, this.length-1);
return this[i];
}