I have an ember function that is continuing the sequence of 2^x where X is the length of the array.
//sequence of ^2: 1, 2, 4, 8, 16, etc...
this.set("numSeq", Ember.Array([1, 2, 4]));
when i push a button I update the sequence using the update
function
update: function() {
var numSeq = this.get("numSeq");
let Sqlength = numSeq.length;
let node = Math.pow(2, Sqlength);
const nodeMax = Math.pow(2, 20);
if (node >= nodeMax) {
this.initializeSequence();
} else if (Sqlength >= 10) {
sequence.pushObject(node);
let smallFry = sequence[0];
sequence.removeObject(smallFry);
} else {
sequence.pushObject(node);
}
}
there are two restrictions to the update function, when a new array input exceeds 2^20 we reset the array, and when the length is greater than 10 we remove the smallest element and still add the new node.
My issue comes when trying to push new objects to array and remove the bottom most element, any method I have used to far slice
, removeat
, removeobject
, it "freezes" the array and just adds the last element not the new node
(example after pressing the button 12 times [1,2,4,...,512,1024,1024,1024]
no errors so i believe this my fault and a misunderstanding of concepts
My error was using the length as the exponent, I just had to use the currentNode*2 to get the next node, not use the length
keeping length at ten always gave me 1024 which is why it would never grow! my own failure but figured it out
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.