This file contains hidden or 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
function findLongestWord(str) { | |
var strArray = str.toUpperCase().split(' ').sort(); | |
var longest = 0; | |
for (var i = 0; i < strArray.length; i++) { | |
if (strArray[i].length > longest) { | |
longest = strArray[i].length; | |
} | |
} | |
return longest; | |
This file contains hidden or 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
function palindrome(str) { | |
var newStr = str.replace(/[^a-zA-Z 0-9]+| /g,'').toLowerCase(); | |
var newStr1 = newStr.split('').reverse().join(''); | |
if(newStr == newStr1){ | |
return true; | |
} | |
else{ | |
return false; | |
} |
This file contains hidden or 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
function factorialize(num) { | |
//check if num == 0 | |
if (num === 0) { | |
return 1; | |
} | |
//else calculate factorial | |
return num * factorialize(num - 1); | |
} | |
//calling the function. this will return 120 | |
factorialize(5); |
This file contains hidden or 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
function reverseString(str) { | |
return str.split("").reverse().join(""); | |
} | |
alert(reverseString("hello")); |
This file contains hidden or 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
<?php | |
function digitSum($n) { | |
$array = str_split($n); | |
$sum = array_sum($array); | |
print $sum; | |
} | |
//calling the function | |
digitSum("123"); |
This file contains hidden or 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
<?php | |
function factorial($n) { | |
$factorial = 1; | |
for($i = $n; $i >= 1; $i--){ | |
$factorial = $factorial * $i; | |
} | |
echo "Factorial of $n is $factorial"; | |
} | |
//calling the function |
This file contains hidden or 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
$(document).ready(function(){ | |
var sum1= 0, res = 0, totalSum = 0; | |
for (var x = 1; x <= 1000; x++) | |
{ | |
if (x % 3 === 0 || x % 5 === 0) | |
{ | |
k = x * 2; | |
sum1 += k; |
NewerOlder