Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
|
|
@ -0,0 +1,20 @@
|
|||
var encodeMTF = function (word) {
|
||||
var init = {wordAsNumbers: [], charList: 'abcdefghijklmnopqrstuvwxyz'.split('')};
|
||||
|
||||
return word.split('').reduce(function (acc, char) {
|
||||
var charNum = acc.charList.indexOf(char); //get index of char
|
||||
acc.wordAsNumbers.push(charNum); //add original index to acc
|
||||
acc.charList.unshift(acc.charList.splice(charNum, 1)[0]); //put at beginning of list
|
||||
return acc;
|
||||
}, init).wordAsNumbers; //return number list
|
||||
};
|
||||
|
||||
var decodeMTF = function (numList) {
|
||||
var init = {word: '', charList: 'abcdefghijklmnopqrstuvwxyz'.split('')};
|
||||
|
||||
return numList.reduce(function (acc, num) {
|
||||
acc.word += acc.charList[num];
|
||||
acc.charList.unshift(acc.charList.splice(num, 1)[0]); //put at beginning of list
|
||||
return acc;
|
||||
}, init).word;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue