-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtask3.js
More file actions
99 lines (83 loc) · 1.83 KB
/
task3.js
File metadata and controls
99 lines (83 loc) · 1.83 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Write a function to check if it is a palindrome or not. A string is said to be palindrome if reverse of the string is same as string.
// Ex 1:
// Input: n = "race car"
// Output: true
// Ex 2:
// Input: n = "not a palindrome"
// Output: false
// Solutions
//Kuldip Mochi
function palindrome(str){
let end = str.length-1;
let start=0;
while(start<end){
if(str[start]==' '){
start++;
}else if(str[end]==' '){
end--;
}else if(str[start]==str[end]){
start++;
end--;
}else{
return false;
}
}
return true;
}
console.log(palindrome("kuddu k"))
//Sachin
function isPalindrome(string){
string=string.replace(/\s/g, ''); // remove one or more white spaces and this is case sensitive
for(i=0;i<string.length/2;i++){
if(!(string.charAt(i)===string.charAt(string.length-1-i))){
console.log(false);
return 0;
}
}
console.log(true);
}
// Naveed
function Palindrome(text) {
let reversedString = text.toLowerCase().split('').reverse().join('');
if(text === reversedString) {
console.log(true)
}else {
console.log(fasle)
}
}
Palindrome('racecar');
//Anusha
function palindrome(a) {
let str = ''
if (a.length == 0) {
return "invalid input"
}
for (let i = 0; i < a.length; i++){
str = a[i] + str
}
if (a == str) {
return true
}
else {
return false
}
}
console.log(palindrome('level'))
//
//Raj-bhat
function palindrome(string) {
var text = '';
if (string.length >0) {
for (let i = 0; i< string.length; i++){
text = string[i] + text; }
if (string == text) {
console.log("entered text is palindrome");
}
else {
console.log("entered text is not a palindrome");
}
}else{
console.log("Empty text");
}
}
palindrome('malayalam');