Skip to content

Instantly share code, notes, and snippets.

@moisesnandres
Created September 3, 2019 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisesnandres/5e8e8846d18d8848abadec8835087fe1 to your computer and use it in GitHub Desktop.
Save moisesnandres/5e8e8846d18d8848abadec8835087fe1 to your computer and use it in GitHub Desktop.
JS exercises
function solution(input, markers) {
const lines = input.split('\n');
const strippedLines = lines.map((line) => {
let strippedLine = line;
markers.forEach((marker) => {
if (line.includes(marker)) {
const index = line.indexOf(marker);
strippedLine = line.slice(0, index);
}
});
return strippedLine.trim();
});
return strippedLines.join('\n');
}
const zero = (operation) => (operation ? operation(0) : 0);
const one = (operation) => (operation ? operation(1) : 1);
const two = (operation) => (operation ? operation(2) : 2);
const three = (operation) => (operation ? operation(3) : 3);
const four = (operation) => (operation ? operation(4) : 4);
const five = (operation) => (operation ? operation(5) : 5);
const six = (operation) => (operation ? operation(6) : 6);
const seven = (operation) => (operation ? operation(7) : 7);
const eight = (operation) => (operation ? operation(8) : 8);
const nine = (operation) => (operation ? operation(9) : 9);
const plus = (a) => (b) => b + a;
const minus = (a) => (b) => b - a;
const times = (a) => (b) => b * a;
const dividedBy = (a) => (b) => Math.floor(b / a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment