/*
- Criar objeto com cada palavra digitada originalmente
- Aplicar regras e criar uma string "formatada"
- Criar objecto com cada palavra do dicionário
- Aplicar regras e criar uma string "formatada"
-Pegar o array de objetos do dicionário e percorrer
-Comparar se a string formatada do dicionário é igual a string formatada do input
-Se for igual, adicionar a palavra original do dicionário dentro do objeto com a palavra original do input
*/
// Add contains method to array prototype
Array.prototype.contains = function(obj) {
return this.indexOf(obj) > -1;
};
var dictionary = [
'angel',
'brave',
'Braev',
'Don',
'Engel',
'go',
'goal',
'son',
'sunny',
'Tom',
'Tooonnnnyyyy'
];
var input = [
'1ton#',
'brief',
'soon'
];
var formattedDictionary = [];
var formattedInput = [];
var formats = [
['a', 'e', 'i', 'o', 'u'],
['c', 'g', 'j', 'k', 'q', 's', 'x', 'y', 'z'],
['b', 'f', 'p', 'v', 'w'],
['d', 't'],
['m', 'n']
];
var output = {};
function applyRules(str) {
// Rule 1 - Remove special characters and numbers
str = str.replace(/(.)(?=.*\1)/g, '');
// Has to run again to ensure that # is not passed
str = str.replace(/[^a-z]/gi, '');
// Rule 2 - Case insensitive
str = str.toLowerCase();
// Rule 3 - Slash character after second position if A, E, I, H, O, U, W or Y
var remchars = str.substring(1, str.length);
remchars = remchars.replace(/[aeihouwy]/ig, '');
str = str[0] + remchars;
// Rule 4 - Apply formats
for (var i = 0, len = str.length; i < len; i++) {
if (formats[0].contains(str[i])) {
var str = str.substring(0, i) + formats[0][0] + str.substring(i + 1);
}
if (formats[1].contains(str[i])) {
var str = str.substring(0, i) + formats[1][0] + str.substring(i + 1);
}
if (formats[2].contains(str[i])) {
var str = str.substring(0, i) + formats[2][0] + str.substring(i + 1);
}
if (formats[3].contains(str[i])) {
var str = str.substring(0, i) + formats[3][0]...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.