This file contains hidden or 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
| const data = require('./data.json'); | |
| const sumArray = (array) => array.reduce((a, b) => a + b, 0); | |
| const results = data.data.reduce((acc, n, idx, arr) => { | |
| const lenIn = arr.length; | |
| const isPastTupleTime = lenIn - idx <= 2; | |
| const newAcc = { | |
| ...acc, | |
| lastValue: n, |
This file contains hidden or 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
| const data = require('./data.json'); | |
| const results = data.data.reduce((acc, val, idx, arr) => { | |
| const [direction, rawValue] = val.split(' '); | |
| const value = Number(rawValue); | |
| switch (direction) { | |
| case 'up': | |
| acc.aim -= value; | |
| break; |
This file contains hidden or 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
| const data = require('./data.json'); | |
| const getFrequency = (arr) => { | |
| const dict = {}; | |
| arr.forEach(function(el) { | |
| if (!dict[el]) dict[el] = 0; | |
| dict[el]++; | |
| }); | |
| return { | |
| leastFrequent: `${Object.keys(dict).find(key => dict[key] === Math.min(...Object.values(dict)))}`, |
OlderNewer