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
// Adapted from : https://www.codewars.com/kata/5390bac347d09b7da40006f6/train/javascript | |
String.prototype.toJadenCase = function () { | |
let str = this.toString(); | |
// split it to an array, | |
// capitalize each item | |
// join it with a space | |
str = str.split(' '); | |
return str.map(word => word.charAt(0).toUpperCase()+ word.slice(1)).join(' '); | |
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
// Addapted from -> https://www.codewars.com/kata/517abf86da9663f1d2000003/train/javascript | |
function toCamelCase(str){ | |
const firstChar = str.charAt(0); | |
// split each word in an array item (using _ or -) | |
const splittedString = str.includes('_') ? str.split('_') : str.split('-'); | |
console.log(splittedString); | |
// check if first char is uppercase | |
let result = ''; | |
if(firstChar.toUpperCase() === firstChar){ |
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
/* | |
* Complete the 'dayOfProgrammer' function below. | |
* | |
* The function is expected to return a STRING. | |
* The function accepts INTEGER year as parameter. | |
*/ | |
const is_leap = (year) => { | |
if(year > 1918){ | |
return year % 4 === 0 ? true : false; | |
}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
// addapted from https://www.hackerrank.com/challenges/divisible-sum-pairs/problem?isFullScreen=true | |
function divisibleSumPairs(n, k, ar) { | |
let counter = 0; | |
for(let i = 0; i< n; i++){ | |
for(let j = 0; j< n; j++){ | |
if(i < j && (ar[i] + ar[j]) % k === 0){ | |
counter +=1; | |
} | |
} | |
} |
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
// Given a square matrix, calculate the absolute difference between the sums of its diagonals. | |
function diagonalDifference(arr) { | |
// Write your code here | |
let right = 0; | |
let left = 0; | |
let interations = arr.length -1; | |
for(let i = 0; i < arr.length; i++){ | |
right += arr[i][i]; |
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
// Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. | |
// You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
// You can return the answer in any order. | |
/** | |
* @param {number[]} nums | |
* @param {number} target | |
* @return {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
/** | |
* @param {string} s | |
* @return {number} | |
*/ | |
var lengthOfLongestSubstring = function(s) { | |
const unique = new Set(s.split('')); | |
return Array.from(unique).length; | |
}; |