Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //number is a string
- function vanity(number, dictionary){
- let dial = {
- 1: "",
- 2: ['a','b','c'],
- 3: ['d','e','f'],
- 4: ['g','h','i'],
- 5: ['j','k','l'],
- 6: ['m','n','o'],
- 7: ['p','q','r','s'],
- 8: ['t','u','v'],
- 9: ['w','x','y','z'],
- 0: ""
- }
- let numArr = [];
- for (let i = 0; i<number.length; i++){
- if (Number(number[i])){
- numArr.push(number[i]);
- }
- }
- console.log(numArr);
- //turn dictionary into array of strings
- //take only words from dictionary where word.length === numArr.length
- //do this by having dictionary words in an array and filter out those that match the above condition
- // let someWords = dictionary.filter(word => word.length === numArr.length)
- let result = [];
- for (let i = 0; i<numArr.length; i++){
- for (let j = 0; j< dial[numArr[i]].length; j++){
- //iterate through letters of a given word from someWords and check to see if
- // dial[numArr[i]].includes that letter
- //if all letters check then push into result
- }
- }
- result.forEach(function(word) {
- return word;
- });
- //at a single digit see if dictionary includes first letter
- //if true then go to next digit
- //when all digits have been checked then push into an array
- //put all the dictonary words in an object so I can access the words
- //key would be an index and value would be word
- //take the number and put it in an array
- //
- //output an array that includes all the dictionary words that match
- }
Add Comment
Please, Sign In to add comment