This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//write a function that checks whether an input is palindrome or not. | |
function check(input){ | |
if(isNaN(input)){ | |
const len = input.length; | |
for (let i = 0; i < len / 2; i++) { | |
if (input[i] !== input[len - 1 - i]) return false; | |
} | |
return true; | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Write a function that counts words in a String | |
function wordCount(str){ | |
let arr=str.split(" "); | |
return arr.filter((word)=>word!="").length; | |
} | |
console.log(wordCount("javaScript exam e bash khabo please wish me luck ")); | |
console.log(wordCount("javaScript exam e bash khabo please wish me luck")); | |
//output: 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//write a function that truncates "a", "z", "c" | |
function truncate(str){ | |
let str2=str.toLowerCase(); | |
let res=""; | |
for(let i=0; i<str2.length; i++){ | |
if(str2[i]=="c"|| str2[i]=="a"||str2[i]=="z") res+=""; | |
else res+=str2[i]; | |
} | |
return res; | |
} |