Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype HTML>
- <head>
- <meta charset="utf-8" />
- </head>
- <body>
- <input id="word" type="text" placeholder="mot" value="Bannana">
- <input id="real_word" type="text" placeholder="mot à deviner" value="Banane">
- <button id="check">Check</button>
- <script>
- var dom_word = document.getElementById("word");
- var dom_real_word = document.getElementById("real_word");
- var dom_check = document.getElementById("check");
- dom_check.onclick = function () {
- alert(check_nearly(dom_word.value, dom_real_word.value));
- }
- function check_nearly(word, real_word) {
- if (word == real_word) return 'Bien joué !';
- var regexs = [];
- var i = real_word.length;
- var j = 0;
- while (i--) {
- while (j < real_word.length && j < (i - 1)) {
- var regex = real_word.substr(0, j) + ".{0,2}" + real_word.substr(j + 1, (i - j - 1)) + ".{0,2}" + real_word.substr(i + 1);
- console.log(regex);
- regexs.push(regex);
- j++;
- }
- j = 0;
- }
- for (regex of regexs) {
- console.log(regex);
- var r = new RegExp(regex);
- if (word.match(r)) {
- return 'Presque !';
- }
- }
- return 'Pas du tout';
- }
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement