Skip to content

Instantly share code, notes, and snippets.

@fzn0x
Created May 19, 2021 15:28
Show Gist options
  • Save fzn0x/10885a90a3626ff95446beab9b2d5b2c to your computer and use it in GitHub Desktop.
Save fzn0x/10885a90a3626ff95446beab9b2d5b2c to your computer and use it in GitHub Desktop.
FIFO Algorithm in Javascript
// define the queue class
class Queue {
constructor(...elements) {
// set array as value of construct args
this.elements = [...elements];
}
push(...args) {
// push arguments to this.elements
return this.elements.push(...args);
}
shift() {
// you can also use splice
//return this.elements.splice(0,1)[0];
return this.elements.shift();
}
// access method as property (modern JS Engine)
get length(){
return this.elements.length;
}
// set method in property (modern JS Engine)
set length(length){
return this.elements.length = length;
}
}
const q = new Queue (5,8) ;
q.push(9);
console.log(q.length);
while(q.length)
console.log(q.shift());
@fzn0x
Copy link
Author

fzn0x commented May 19, 2021

FIFO (First In First Out) adalah teknik untuk mengatur persediaan barang yang merupakan hasil dari keputusan manajerial dalam kegiatan normal perusahaan, di mana barang yang pertama masuk berarti barang tersebutlah yang pertama harus keluar.

@fzn0x
Copy link
Author

fzn0x commented May 19, 2021

Example in Inventory Case Study
download (36)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment