-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge_9.js
More file actions
56 lines (51 loc) · 977 Bytes
/
Copy pathchallenge_9.js
File metadata and controls
56 lines (51 loc) · 977 Bytes
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
function Stacker(){
var stack = [];
this.size = function() {
return stack.length;
}
this.push = function() {
for(var i =0; i < arguments.length; i+= 1) {
stack.push(arguments[i]);
}
}
this.pop = function(){
if (stack.length > 0 ) {
return stack.pop();
} else {
return null;
}
}
}
function altPop(o) {
var j = o.size()
, i = 0
, output = []
, p;
while (i < j ) {
p = o.pop();
if (i % 2 === 0) {
output.push( p );
}
i += 1;
}
return output.join(' ');
}
var fs = require("fs")
, nums
, j = 0
, i = 0
, _obj
;
fs.readFileSync(process.argv[2]).toString().split('\n').forEach(function (line) {
if (line !== "") { // ignore empty lines
nums = line.split(' ');
i = 0
j = nums.length;
_obj = new Stacker();
while (i < j) {
_obj.push(nums[i]);
i += 1;
}
console.log( altPop(_obj) );
}
});