Skip to content

Instantly share code, notes, and snippets.

@io-developer
Last active March 4, 2018 13:09
Show Gist options
  • Save io-developer/fa9b063df1c621e44370439eb2e7dc41 to your computer and use it in GitHub Desktop.
Save io-developer/fa9b063df1c621e44370439eb2e7dc41 to your computer and use it in GitHub Desktop.
function calc(input) {
var checksum = 0;
input.split('\n').forEach(row => {
var nums = row.split('\t').map(n => parseInt(n));
var min = nums.reduce((a, b) => Math.min(a, b));
var max = nums.reduce((a, b) => Math.max(a, b));
checksum += max - min;
});
return checksum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment