Skip to content

Commit 5427ec6

Browse files
committed
iniitla commit
0 parents  commit 5427ec6

File tree

9 files changed

+356
-0
lines changed

9 files changed

+356
-0
lines changed

.idea/jsAlgo.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/watcherTasks.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

caesarCipher.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const caesarCipher = (mainString, num, cb) => {
2+
console.log(mainString);
3+
var newString = '', currentIndex, newIndex;
4+
5+
myString = mainString.toLowerCase().split('');
6+
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
7+
8+
var index = 0;
9+
myString.map((val) => {
10+
if (!alphabet.includes(val)) {
11+
newString += val;
12+
index++;
13+
return;
14+
}
15+
16+
currentIndex = alphabet.indexOf(val);
17+
18+
newIndex = (currentIndex + num) % 26;
19+
20+
if (newIndex < 0) newIndex += 26;
21+
22+
if (mainString.charAt(index) == val.toUpperCase()) {
23+
console.log('Uppercase');
24+
newString += alphabet[newIndex].toUpperCase();
25+
} else {
26+
newString += alphabet[newIndex];
27+
}
28+
29+
index ++;
30+
});
31+
32+
cb(newString);
33+
};
34+
35+
caesarCipher('Zoo Keeper', 2, (result) => {
36+
console.log('Result is: ' + result);
37+
});
38+

fizzBuzz.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function fizzBuzz(num) {
2+
for (var index = 1; index <= num; index++) {
3+
if ((index % 3 == 0) && (index % 5 == 0)) console.log('FizzBuzz');
4+
else if (index % 3 == 0) console.log('Fizz');
5+
else if (index % 5 == 0) console.log('Buzz');
6+
else console.log(index);
7+
}
8+
}
9+
10+
fizzBuzz(20);

harmlessRansomNote.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const harmlessRansomNotes = (noteText, magazineText) => {
2+
const noteArr = noteText.split(' '),
3+
magazineArr = magazineText.split(' ');
4+
5+
let magazineObj = {};
6+
7+
magazineArr.map((val) => {
8+
if (magazineArr[val]) magazineArr[val]++;
9+
else magazineArr[val] = 1;
10+
});
11+
12+
let flag = true;
13+
14+
noteArr.map((val) => {
15+
if (typeof magazineArr[val] == 'undefined' || magazineArr[val] <= 0) flag = false;
16+
else magazineArr[val]--;
17+
});
18+
19+
return flag;
20+
};
21+
22+
if (harmlessRansomNotes('this is a secret note for you from a secret admirer', 'puerto rico is a place of great wonder and excitement it has many waterfall locatoins that i am an admirer of you must hike quite a distance to find the secret places as they are far from populated areas but it is worth the effort a tip i have for you is to go early in the morning when it is not so hot out also secret that you must wear hiking boots this is one of the best places i have ever visited')) console.log('True');
23+
else console.log('False');

isPalindrome.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const isPalindrome = (word, cb) => {
2+
const arr = word.toLowerCase().split(''),
3+
validCharacters = 'abcdefghijklmnopqrstuvwxyz'.split('');
4+
var wordArr = [];
5+
6+
wordArr = arr.filter((val) => {
7+
if (validCharacters.includes(val)) return val;
8+
});
9+
10+
var length = wordArr.length;
11+
12+
for(let index1=0, index2=length-1; index1 < (length/2); index1++, index2--) {
13+
if (wordArr[index1] == ' ' || validCharacters.includes(wordArr[index1]) == false ) {
14+
index1++;
15+
} else if (wordArr[index2] == ' ' || validCharacters.includes(wordArr[index2]) == false) {
16+
index2--;
17+
}
18+
if (wordArr[index1] != wordArr[index2]) return cb(false);
19+
}
20+
cb(true);
21+
};
22+
23+
isPalindrome("Madam I'm Adam", (isPalindrome) => {
24+
if (isPalindrome == true) console.log('True');
25+
else console.log('False');
26+
});

0 commit comments

Comments
 (0)