Skip to content

Commit dcc7e38

Browse files
Merge pull request Nivedita-coder#61 from arwysyah/arwysyah
add palindrome and matrix transpose
2 parents 2d24c8e + 978b0ce commit dcc7e38

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎Javascript_Algo/MatrixTranspose.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let mathData = [
2+
[1, 2, 3],
3+
[4, 5, 6],
4+
[7, 8, 9],
5+
];
6+
function transMat(matrix) {
7+
let newMatx = [];
8+
for (let i = 0; i < matrix[0].length; i++) {
9+
let newMat = [];
10+
for (let j = 0; j < matrix[0].length; j++) {
11+
newMat.push(matrix[j][i]);
12+
}
13+
newMatx.push(newMat);
14+
}
15+
// console.log(newMat)
16+
return newMatx;
17+
}
18+
console.table(transMat(mathData));

‎Javascript_Algo/palindrome.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function palindrome(str, word) {
2+
let jum = 0;
3+
function count(word) {
4+
while (word.length >= str.length) {
5+
if (word.substring(0, str.length) == str) {
6+
jum++;
7+
}
8+
word = word.substring(1);
9+
}
10+
}
11+
count(word);
12+
count(reverseString(word));
13+
return jum;
14+
}
15+
function reverseString(str) {
16+
return str;
17+
}
18+
console.log(palindrome("nana", "banananana"));

0 commit comments

Comments
 (0)