A little late to starting on this, but I am excited to get going!
JS
Part 1 (A little bit trolly)
var fs = require('fs'); fs.readFile('./numbers.txt', 'utf8', function(err, contents) { console.log(eval(contents)); });
Part 2 (could probably use some optimizations)
var fs = require('fs'); const hash = {}; fs.readFile('./numbers.txt', 'utf8', function(err, contents) { const lines = contents.split('\n'); let current = 0; let i = 0; while(true) { if(i === lines.length-1) { i = 0; } const line = lines[i]; const old = current; const num = Number(line) current += num; if(hash[current]) { console.log(current); break; } hash[current] = true; console.log(old, '+', num, '->', current); i++; } });
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A little late to starting on this, but I am excited to get going!
JS
Part 1 (A little bit trolly)
Part 2 (could probably use some optimizations)