Last active
April 6, 2019 18:40
-
-
Save enricopolanski/336f3e902d7887329eb7b3d0f8636cbf 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 { | |
const decodedString = [stringWithoutNonUnicode] | |
.map(splitByWhitespace)[0] | |
.map(replaceWithOriginal(listOfDecodedWords)) | |
.join("") | |
.replace(/./g, (char, index) => | |
!unicodeWord.test(char) ? str[index] : char | |
); | |
console.log(decodedString); | |
return { | |
errorMessage: "", | |
decodedString: decodedString | |
}; | |
} catch (e) { | |
return { | |
errorMessage: e, | |
decodedString: "" | |
}; | |
} |
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
import _ from "lodash"; | |
import isMiddlePermutable from "../strings/isMiddlePermutable"; | |
export default strList => { | |
return inputString => { | |
const replacement = strList.find(originalString => | |
_.isEqual( | |
_.sortBy(inputString.split("")), | |
_.sortBy(originalString.split("")) | |
) | |
); | |
console.log(replacement); | |
if (!!replacement && isMiddlePermutable(inputString)) { | |
console.log("here"); | |
throw Error(`${inputString} has no decoder word`); | |
} else { | |
return replacement; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment