Skip to content

Instantly share code, notes, and snippets.

View h2othedev's full-sized avatar
💧
Water The Dev 🚒

Abdelhady Salah h2othedev

💧
Water The Dev 🚒
View GitHub Profile
@h2othedev
h2othedev / toJadenCase.js
Created June 12, 2022 20:36
toJadenCase.js - A String method that capitalizes the first letter of every word in the string
/**
* @description A String method that capitalizes the first letter of every word in the string
* @returns a new string with the description above applied
*/
String.prototype.toJadenCase = function () {
const str = this.toString()
return str.split(' ').map((word) => word[0].toUpperCase() + word.substring(1)).join(' ')
}
@h2othedev
h2othedev / partsSums.js
Last active June 13, 2022 01:11
partsSums.js - enter a list and get the sum of its parts (numbers)
/**
* @name partsSums.js
* @description takes a list (array) and returns the sums of the parts of this array
* @param ls - the list of numbers
* @returns the sums of its parts
*
* Example:
* ls = [0, 1, 3, 6, 10]
* ls = [1, 3, 6, 10]
* ls = [3, 6, 10]
@h2othedev
h2othedev / narcissistic.js
Created June 12, 2022 17:55
narcissistic.js - returns true if a narcissistic number, false if otherwise
/**
* More details on Narcissistic numbers can be found here
* https://en.wikipedia.org/wiki/Narcissistic_number
*
* @param value number to check
* @returns true if a narcissistic number, false if otherwise
*
*/
const narcissistic = (value) => {
@h2othedev
h2othedev / rotateRight.js
Created June 11, 2022 23:53
rotateRight.js - Move/Rotate elements in an Array by "k" steps
/**
*
* @param nums - the array to rotate
* @param k - the number of steps to move elements by
* @returns - the new rotated array
*/
const rotateRight = (nums, k) => {
const elementsToUnshift = nums.filter((_num, idx) => idx + k >= nums.length)
let numsRotated = nums.filter((num) => !elementsToUnshift.includes(num))