Skip to content

Instantly share code, notes, and snippets.

@enricopolanski
Last active April 6, 2019 18:40
Show Gist options
  • Save enricopolanski/336f3e902d7887329eb7b3d0f8636cbf to your computer and use it in GitHub Desktop.
Save enricopolanski/336f3e902d7887329eb7b3d0f8636cbf to your computer and use it in GitHub Desktop.
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: ""
};
}
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