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
/** | |
* @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(' ') | |
} |
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
/** | |
* @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] |
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
/** | |
* 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) => { |
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 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)) |