Created
July 1, 2017 14:24
-
-
Save primayudantra/c1011d5a816196876c87cee69ba5f1a2 to your computer and use it in GitHub Desktop.
fh - berlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = [2, 4, 6, 8, 9, 15] | |
let b = ['4', '16', '64'] | |
function question_1(){ | |
while(b.length > 0){ b.pop(); } | |
a.concat(b).forEach(function(data){ | |
b.push(data); | |
}) | |
console.log(b) //print all data b | |
} | |
question_1() | |
// --------------------------------------------------------------- | |
let requests = [ | |
{requestId: 'poiax', startedAt: 1489744808, ttl: 8}, | |
{requestId: 'kdfhd', startedAt: 1489744803, ttl: 3}, | |
{requestId: 'uqwyet', startedAt: 1489744806, ttl: 12}, | |
{requestId: 'qewaz', startedAt: 1489744810, ttl: 1} | |
] | |
function question_2(requests){ | |
var minimal = requests[0].startedAt; | |
var maximal = 0; | |
requests.forEach(function(data){ | |
minimal = minimal, maximal = maximal | |
if(data.startedAt <= minimal) minimal = data.startedAt; | |
if((data.startedAt + data.ttl) >= maximal){ | |
maximal = data.startedAt + data.ttl | |
} | |
}) | |
return maximal - minimal; | |
} | |
console.log(question_2(requests)) | |
// --------------------------------------------------------------- | |
let fs = require('fs'), | |
fn = process.argv[2]; | |
function check(b){ | |
if(b.length == 3){ | |
return 'triangle'; | |
} | |
if(b.length == 4 && b[0] == b[1] && b[2] == b[3] && b[0] == b[2]){ | |
return 'square'; | |
} | |
if(b.length == 4 && b[0] == b[2] && b[1] == b[3]){ | |
return 'rectangle'; | |
} | |
return 'Everything Else'; | |
} | |
fs.readFile(fn, 'utf8', function(err,data){ | |
if (err) console.log(err) | |
let a = data, | |
b = a.split(','), | |
b_arrNum = [], | |
name = ''; | |
for(var idx = 0;idx < b.length; idx++){ | |
b[idx] = parseInt(b[idx], 10) | |
} | |
console.log(check(b)) | |
var sum = b.reduce((a,b) => a+b, 0) // sum all side lengths | |
console.log(sum) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment