Created
December 16, 2016 23:54
-
-
Save upkarlidder/f3d38074eb7f52515f7954b916596b0e to your computer and use it in GitHub Desktop.
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
//TRY 1 | |
// const nextCharForNumberString = function(str){ | |
// const trimmed = str.trim(); | |
// const number = parseInt(trimmed); | |
// const nextNumber = number + 1; | |
// return String.fromCharCode(nextNumber); | |
// } | |
//TRY 2 | |
// const nextCharForNumberString = function(str){ | |
// return String.fromCharCode((parseInt(str.trim()) + 1)); | |
// } | |
//TRY 3 | |
const Box = function(x){ | |
return { | |
map: function(f){ | |
return Box(f(x)) | |
}, | |
inspect: function(){ | |
return `Box(${x})`; | |
}, | |
fold: function(f){ | |
return f(x); | |
} | |
} | |
} | |
const nextCharForNumberString = function(str){ | |
return Box(str) | |
.map(s => s.trim()) | |
.map(s => parseInt(s)) | |
.map(i => i + 1) | |
.map(i => String.fromCharCode(i)) | |
.fold(c => c); | |
} | |
const result = nextCharForNumberString(' 64 '); | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment