Skip to content

Instantly share code, notes, and snippets.

View blessedjasonmwanza's full-sized avatar
💭
Open to remote work - Fullstack Web Applications & Management Systems Developer

Blessed Jason Mwanza blessedjasonmwanza

💭
Open to remote work - Fullstack Web Applications & Management Systems Developer
View GitHub Profile
@blessedjasonmwanza
blessedjasonmwanza / JadenCasingStrings.js
Created May 3, 2022 14:23
Capitalize first character of each word
// 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(' ');
@blessedjasonmwanza
blessedjasonmwanza / toCamelCase.js
Created April 28, 2022 14:42
Convert string to camel case - CodeWar Challenge
// 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){
@blessedjasonmwanza
blessedjasonmwanza / day-of-the-programmer.js
Created March 18, 2022 07:44
Complete the dayOfProgrammer function in the editor below. It should return a string representing the date of the 256th day of the year given. dayOfProgrammer has the following parameter(s): year: an integer
/*
* 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{
@blessedjasonmwanza
blessedjasonmwanza / divisible-sum-pairs.js
Created March 8, 2022 07:35
divisible sum pairs - HackerRank challenge solution
// 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;
}
}
}
@blessedjasonmwanza
blessedjasonmwanza / diagonal-difference.js
Created February 25, 2022 07:36
HackerRank Diagonal difference challenge solution JS
// 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];
@blessedjasonmwanza
blessedjasonmwanza / twoSum.js
Created February 22, 2022 07:32
Two Sum LeetCode Challenge
// 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[]}
*/
@blessedjasonmwanza
blessedjasonmwanza / lengthOfLongestSubstring.js
Created February 3, 2022 07:32
Count length of unique characters in a string
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function(s) {
const unique = new Set(s.split(''));
return Array.from(unique).length;
};