Mercurial > hg > webaudioevaluationtool
comparison core.js @ 898:070a90d1117c
Merge from the default branch
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Tue, 16 Jun 2015 14:14:08 +0100 |
parents | b7f262db9886 |
children | d350e20bddd1 |
comparison
equal
deleted
inserted
replaced
897:b7f262db9886 | 898:070a90d1117c |
---|---|
1098 | 1098 |
1099 function randomiseOrder(input) | 1099 function randomiseOrder(input) |
1100 { | 1100 { |
1101 // This takes an array of information and randomises the order | 1101 // This takes an array of information and randomises the order |
1102 var N = input.length; | 1102 var N = input.length; |
1103 var K = N; | 1103 |
1104 var inputSequence = []; // For safety purposes: keep track of randomisation | |
1105 for (var counter = 0; counter < N; ++counter) | |
1106 inputSequence.push(counter) // Fill array | |
1107 var inputSequenceClone = inputSequence.slice(0); | |
1108 | |
1104 var holdArr = []; | 1109 var holdArr = []; |
1110 var outputSequence = []; | |
1105 for (var n=0; n<N; n++) | 1111 for (var n=0; n<N; n++) |
1106 { | 1112 { |
1107 // First pick a random number | 1113 // First pick a random number |
1108 var r = Math.random(); | 1114 var r = Math.random(); |
1109 // Multiply and floor by the number of elements left | 1115 // Multiply and floor by the number of elements left |
1110 r = Math.floor(r*input.length); | 1116 r = Math.floor(r*input.length); |
1111 // Pick out that element and delete from the array | 1117 // Pick out that element and delete from the array |
1112 holdArr.push(input.splice(r,1)[0]); | 1118 holdArr.push(input.splice(r,1)[0]); |
1119 // Do the same with sequence | |
1120 outputSequence.push(inputSequence.splice(r,1)[0]); | |
1113 } | 1121 } |
1122 console.log(inputSequenceClone.toString()); // print original array to console | |
1123 console.log(outputSequence.toString()); // print randomised array to console | |
1114 return holdArr; | 1124 return holdArr; |
1115 } | 1125 } |
1116 | 1126 |
1117 function returnDateNode() | 1127 function returnDateNode() |
1118 { | 1128 { |