Added S64

master
Ron Reciproco 12 months ago
parent 151a35c28f
commit 3753f1d9e6

@ -0,0 +1 @@
/node_modules

@ -0,0 +1,10 @@
image: node:latest
stages:
- test
test:
stage: test
script:
- npm install
- npm test

@ -0,0 +1,5 @@
To start using the built-in tests, run <code>npm install</code> first then issue the <code>npm test</code> at the root directory of this project.
WARNING: Do not change any code inside <code>test.js</code>.
[Link to Solution](https://gitlab.com/zuitt-coding-bootcamp-curricula/courses/wdc028v1.5a/-/tree/main/fullstack/s54-solution)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,14 @@
{
"name": "s54",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"author": "",
"license": "ISC",
"dependencies": {
"jest": "^26.6.3"
}
}

@ -0,0 +1,40 @@
let collection = [];
// Write the queue functions below.
function print() {
return collection;
}
function enqueue(value) {
collection.push(value);
return collection;
}
function dequeue() {
collection.shift();
return collection;
}
function front() {
if (collection.length === 0) {
return undefined;
}
return collection[0];
}
function size() {
return collection.length;
}
function isEmpty() {
return collection.length === 0;
}
module.exports = {
print,
enqueue,
dequeue,
front,
size,
isEmpty
};

@ -0,0 +1,21 @@
<script>
let collection = [];
function addToStack(element) {
collection.push(element);
return collection;
}
function removeFromStack() {
collection.pop();
return collection;
}
function peek() {
return collection[collection.length-1];
}
function getLength() {
return collection.length;
}
</script>

@ -0,0 +1,59 @@
// This is the file to check whether your answer is correct or wrong.
// Do not change anything in this file.
const assert = require('assert');
const queue = require('./queue');
describe('[1] Print queue elements.', function() {
it('The printed value is an empty array. RESULT = []', function() {
expect(queue.print()).toEqual([]);
});
});
describe('[2] Enqueue a new element.', function() {
it('The value has been enqueued. RESULT = [\'John\']', function() {
expect(queue.enqueue('John')).toEqual(['John']);
});
});
describe('[3] Enqueue another element.', function() {
it('The value has been enqueued. RESULT = [\'John\', \'Jane\']', function() {
expect(queue.enqueue('Jane')).toEqual(['John', 'Jane']);
});
});
describe('[4] Dequeue the first element.', function() {
it('The value has been dequeued. RESULT = [\'Jane\']', function() {
expect(queue.dequeue()).toEqual(['Jane']);
});
});
describe('[5] Enqueue another element.', function() {
it('The value has been enqueued. RESULT = [\'Jane\', \'Bob\']', function() {
expect(queue.enqueue('Bob')).toEqual(['Jane', 'Bob']);
});
});
describe('[6] Enqueue another element.', function() {
it('The value has been enqueued. RESULT = [\'Jane\', \'Bob\', \'Cherry\']', function() {
expect(queue.enqueue('Cherry')).toEqual(['Jane', 'Bob', 'Cherry']);
});
});
describe('[7] Get first element.', function() {
it('The first value has been retrieved. RESULT = \'Jane\'', function() {
expect(queue.front()).toEqual('Jane');
});
});
describe('[8] Get queue size.', function() {
it('The size of the queue has been retrieved. RESULT = 3', function() {
expect(queue.size()).toEqual(3);
});
});
describe('[8] Check if queue is not empty.', function() {
it('The result has been retrieved. RESULT = false', function() {
expect(queue.isEmpty()).toEqual(false);
});
});
Loading…
Cancel
Save