UNPKG

unscramble

Version:

unscramble scrambled text

39 lines (28 loc) 746 B
var words = require('an-array-of-english-words') exports.scramble = function(word) { word = word.split(''); var num = 0; var scramble = ''; while(word.length > 0) { num = word.length * Math.random() << 0; scramble += word[num]; word.splice(num, 1); } return scramble; } module.exports = function(word) { word = word.toLowerCase(); var matches = [] var sortedWord = word.split('').sort().join('') words.forEach((x) => { if(matches.length >= 30) return; if (sortedWord.length == x.length) { var x2 = x.split('').sort().join('') if (sortedWord == x2) { matches.push(x) } } }); if(matches.length == 0) matches = ["No results found."]; return matches; }