-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
25 lines (25 loc) · 882 Bytes
/
util.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
// checks words for palindrome and returns boolean value
module.exports.isPalindrome = (word) => {
word= word.toLowerCase();
let reverseWord = word.split('').reverse().join('');
return word === reverseWord;
}
// sanitises array from spaces and empty element
module.exports.removeWhiteSpaceFromArray = (array)=>{
return array.filter((arrEle) => {
return (arrEle != ' ' && arrEle!='')
});
}
// sanitises string from punctuation markes and special characters
module.exports.removePunctuationMarks = (line)=>{
//return line.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"");
return line.replace(/[\\.,@+[|"'<>?\/#!$%\^&\*;:{}=\-_`~()]/g,"");
}
// flattens the level one nested array
module.exports.nestArrToFlatObject = (nestedArr) => {
let palObj= {};
nestedArr.map((eachEle)=>{
palObj[eachEle[0]] = eachEle[1];
});
return palObj;
}