-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagram.js
38 lines (29 loc) · 937 Bytes
/
anagram.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const input = ["APPLE", 0923, "Crisps", false, "magazine", "lol", "cHaIr", "teleVISION", "LOL", 02, true, "bob" ]
const output = []
const filterOutNonStringData = (input) => input.filter((item) => {
const cleansedData = []
let i = 0
let j = 0
if(typeof(item) === "string"){
return cleansedData.push(item)
}
})
const identifyAnagram = () => {
const cleanData = filterOutNonStringData(input)
cleanData.filter((word) => {
if(word.split("").reverse().join("") === word) {
return output.push(word)
}
})
}
identifyAnagram(input)
console.log("The following words were anagrams: ", output)
/*
Given an array of words (of known length of 10). Find any anagrams that exist within and output them
1. Remove non string data types
2. Remove duplicate words
Improvements
1. lowercase words and remove string sensitivity
2. Use reduce
3. Make more functional and stop mutating data.
*/