Created
September 3, 2019 19:28
-
-
Save moisesnandres/5e8e8846d18d8848abadec8835087fe1 to your computer and use it in GitHub Desktop.
JS exercises
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
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