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
function scrabbleScore(str){ | |
var value = 0; | |
for(i = 0 ; i< str.length; i++){ | |
switch (true){ | |
case( /[dg]/i.test(str[i])): | |
value += 2; | |
break; | |
case( /[bcmp]/i.test(str[i])): | |
value += 3; | |
break; |
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
function palindrome(string) { | |
let newString = string.replace(/\W/g, '').toLowerCase(); | |
let stringLength = newString.length, midleString = stringLength % 2 === 0 ? stringLength / 2 : ((stringLength / 2)+1); | |
for(i = 0; i< midleString; i++){ | |
if(newString[i] != newString[stringLength - 1 - i]){ | |
return false; | |
} | |
} | |
return true; |
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
function christmasTree(height) { | |
var value = ""; | |
for(i = 1; i<= height; i++ ) { | |
var blank = " ".repeat(height-i); | |
value += blank + "*".repeat(1+((i-1)*2)) + blank; | |
value += i < height ? "\n" : ""; | |
} | |
return value | |
} |
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
function songDecoder(song){ | |
return song.replace(/(WUB)+/g, " ").trim(); | |
} |
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
function toWeirdCase(string){ | |
let newString = string.split(' '); | |
for(let i = 0; i < newString.length; i++){ | |
newString[i] = newString[i].weird(); | |
} | |
return newString.join(' '); | |
} | |
String.prototype.weird = function( ){ | |
var newString = ''; |
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
function countSquares(n){ | |
let value = 0; | |
for(var i = 1; i<=n; i++){ | |
value += i * i; | |
} | |
return value; | |
} |
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
function humanReadable(seconds) { | |
var hours = seconds / 3600, minutes = seconds / 60 % 60, newSeconds = seconds % 60 ; | |
return formatDate(hours) +':' + formatDate(minutes)+':'+formatDate(newSeconds) | |
} | |
function formatDate(n){ | |
var number = Number.parseInt(n) | |
return number > 9? number : '0'+number; | |
} |
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
var palindromeChainLength = function(n) { | |
let notIsPalindrome = true, index = 0, value=n; | |
while(notIsPalindrome){ | |
let reversed = Number.parseInt(value.toString().split('').reverse().join('')); | |
if(value == reversed){ | |
notIsPalindrome = false; | |
}else{ | |
index++; | |
value += reversed; | |
} |
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
function toUnderscore(string) { | |
return string.toString().replace(/[A-Z]/g,function(element, index){ | |
element = element.toLowerCase(); | |
return index == 0 ? element :'_'+ element | |
}); | |
} |
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
public class SequenceSum { | |
public static int[] sumOfN(int n) { | |
boolean isNegative = n < 0; | |
int arraySize = Math.abs(n)+1; | |
int[] result= new int[arraySize]; | |
for(int i = 1; i < arraySize;i++){ | |
result[i] = isNegative? result[i-1] - i: result[i-1] + i; | |
} | |
return result; | |
} |
OlderNewer