This file contains hidden or 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
/* | |
A happy number is a number which eventually reaches 1 | |
when replaced repeatedly by the sum of the square of | |
its digits. If it loops endlessly in a cycle, | |
then it is not a happy number. | |
For example, starting with 19, the sequence is: 1² + 9² = 82, | |
8² + 2² = 68, | |
6² + 8² = 100, | |
1² + 0² + 0² = 1. | |
Hence, 19 is a happy number. |
This file contains hidden or 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
/* | |
Find the Second Largest Number in an Array | |
The Challenge | |
Difficulty: Medium | |
Topic: Array Manipulation | |
Description | |
Write a JavaScript function that takes an array of numbers |
This file contains hidden or 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
/* | |
Calculate Unique Elements in a Square Matrix | |
Given a square matrix, write a function that computes the number of unique elements in the matrix. A square matrix is a two-dimensional array where the number of rows is equal to the number of columns. | |
Example: | |
Input: [[2, 3, 2], [9, 3, 1], [1, 2, 5]] | |
Output: 5 | |
*/ | |
int countUniqueElements(int[][] matrix) => matrix.SelectMany(m => m).Distinct().Count(); |
This file contains hidden or 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
/* | |
Find the Maximum Depth of a Nested Array | |
Develop a function to find the maximum depth of nested arrays. | |
The function will receive an array as its input, | |
which can contain other arrays to any depth, | |
and it should return the maximum depth integer. | |
Example: | |
Input: [1, [2, [3, [4]], 5], 6] | |
Output: 4 |
This file contains hidden or 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
/* | |
Find Smallest Missing Positive Integer | |
Write a function that finds the smallest positive integer | |
that is missing from an unsorted array of integers. | |
Your function should run with an expected time complexity of O(n). | |
Example: | |
Input: [-1, 4, 2, 1, 9, 10] | |
Output: 3 | |
*/ |
This file contains hidden or 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
/* The Challenge | |
Difficulty: Easy | |
Topic: Array manipulation | |
Description | |
Given an array of numbers, calculate the sum of digits for each number | |
and return a new array containing these sums in the same order. | |
*/ |
This file contains hidden or 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
/* | |
The Challenge | |
Difficulty: Easy | |
Topic: Array Manipulation | |
Description | |
Given an array of integers, write a function to calculate the product | |
of all non-zero elements in the array. | |
If no non-zero element exists, return 1. |
This file contains hidden or 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 static int AskGunSkill(IIO io) | |
{ | |
io.Display("How good a shot are you with your rifle?"); | |
io.Display(" (1) Ace Marksman, (2) Good Shot, (3) Fair to Middlin'"); | |
io.Display(" (4) Need more practice, (5) Shaky Knees"); | |
io.Display("Enter one of the above . The better you claim you are, the"); | |
return io.InputValue("faster you'll have to be with your gun to be successful... ", 1, "Enter 1-5", 5, | |
"Enter 1-5"); | |
} |
This file contains hidden or 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 static void UpdateFromText<T>(this T target, string changes, bool trueCase = true) | |
where T : class | |
{ | |
var propsTarget = target.GetType().GetProperties(); | |
var parts = changes.Split('='); | |
if (parts.Length != 2) | |
throw new ArgumentOutOfRangeException(parts[0], $"{parts[0]} is not a property of the target"); | |
var pT = propsTarget.FirstOrDefault(t => t.Name == parts[0]); | |
if (pT == null) |
This file contains hidden or 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 static void UpdateFromText<T>(this T target, IDictionary<string, object> changes) | |
where T : class | |
{ | |
foreach (var kvp in changes) | |
{ | |
var propsTarget = typeof(T).GetProperty(kvp.Key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); | |
if (propsTarget == null) | |
//throw new ArgumentOutOfRangeException(nameof(changes), $"{kvp.Key} is not a property of the target"); | |
continue; |
NewerOlder