-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortArray.js
More file actions
120 lines (76 loc) · 2.64 KB
/
sortArray.js
File metadata and controls
120 lines (76 loc) · 2.64 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$(document).ready(function(){
// var myArray = [0.2867, 0.833, 1.576, 0.19, 0.688, 0.22, 0.572, .167, 0.643, 0.921, "-", "-", 0.222, 1.466789, 0.1, 0.714, 1.115, 35.98, 55.578, 1993, 202.3, 202.0, 20.005];
// var myNewArray = []
// var decimalPlace = null
// var j;
// /*This function checks for the length of the array
// Pulls the value
// assigns the value to a variable
// converts it to a precision of 3 places
// Pushes the value to the new array
// and checks the value being pushed to the array by logging the array
// */
// for (j=0; j<myArray.length; j++) {
// if (myArray[j] === "-"){
// decimalPlace = 000;
// myNewArray.push(decimalPlace);
// }
// /*
// If this is a number then this is supposed to make sure there is not a zero in the
// front of the decimal. if there is a zero we will remove it.
// */
// else{
// decimalPlace = myArray[j].toPrecision(3)
// console.log(decimalPlace)
// myNewArray.push(decimalPlace);
// console.log(myNewArray)
// myNewArray = myNewArray.map(function(decimalPlace){
// decimalPlace = Number(decimalPlace).toFixed(3);
// if(decimalPlace === "-") return '.000';
// return decimalPlace[0] === '0'? decimalPlace.slice(1) : decimalPlace
// })
// }
// }
// /*After the new array has been filled
// This will sort the new array
// log to see the new order of the array
// and alert that the new array in order
// */
// myNewArray.sort()
// console.log(myNewArray);
// /*
// This block of code makes a formatte way to present it so that it can be viewed in the html
// */
// var k;
// var formatSentence = "";
// for(k=0; k<myNewArray.length; k++){
// formatSentence += myNewArray[k]+ ", "
// }
// console.log(formatSentence)
// $(".arrayValue").text(formatSentence);
var complete = false;
var myNewArray = [];
var sortedArray = [];
$("#adds").click(function(event){
event.preventDefault();
var numb = $('#addNumber').val();
myNewArray.push(parseFloat(numb));
var k;
var formatSentence = "";
for(k=0; k<myNewArray.length; k++){
formatSentence += myNewArray[k]+ ", "
}
console.log(formatSentence)
$(".arrayValue").text(formatSentence);
});
$("#sort").click(function(event){
event.preventDefault();
var sorted = [ new Float32Array(myNewArray).sort()]
var formatSentence = "";
for(k=0; k<sorted.length; k++){
formatSentence += sorted[k]+ ", "
}
console.log(formatSentence)
$(".arrayValue").text(formatSentence);
});
});