Skip to content

Instantly share code, notes, and snippets.

View Nicknyr's full-sized avatar

Nick Kinlen Nicknyr

  • South Florida
View GitHub Profile
@Nicknyr
Nicknyr / findEmailDomain.js
Created April 5, 2020 01:52
CodeSignal - Find Email Domain
/*
An email address such as "John.Smith@example.com" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com").
The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses.
Given a valid email address, find its domain part.
Example
For address = "prettyandsimple@example.com", the output should be
@Nicknyr
Nicknyr / growingPlant.js
Created March 31, 2020 04:05
CodeSignal - Growing Plant
/*
Caring for a plant can be hard work, but since you tend to it regularly, you have a plant that grows consistently. Each day, its height increases by a fixed amount represented by the integer upSpeed. But due to lack of sunlight, the plant decreases in height every night, by an amount represented by downSpeed.
Since you grew the plant from a seed, it started at height 0 initially. Given an integer desiredHeight, your task is to find how many days it'll take for the plant to reach this height.
Example
For upSpeed = 100, downSpeed = 10, and desiredHeight = 910, the output should be
growingPlant(upSpeed, downSpeed, desiredHeight) = 10.
@Nicknyr
Nicknyr / differentSymbolsNaive.js
Created March 30, 2020 01:34
CodeSign - Different Symbols Naive
/*
Given a string, find the number of different characters in it.
Example
For s = "cabca", the output should be
differentSymbolsNaive(s) = 3.
There are 3 different characters a, b and c.
*/
@Nicknyr
Nicknyr / firstDigit.js
Created March 30, 2020 01:13
CodeSignal - First Digit
/*
Find the leftmost digit that occurs in a given string.
Example
For inputString = "var_1__Int", the output should be
firstDigit(inputString) = '1';
For inputString = "q2q-q", the output should be
firstDigit(inputString) = '2';
For inputString = "0ss", the output should be
@Nicknyr
Nicknyr / circleOfNumbers.js
Created March 29, 2020 00:31
CodeSignal - Circle of Numbers
/*
Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1 are neighboring, too).
Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.
Example
For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.
*/
@Nicknyr
Nicknyr / alphabeticShift.js
Created March 29, 2020 00:06
CodeSignal = Alphabetic Shift
/*
Given a string, your task is to replace each of its characters by the next one in the English alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a).
Example
For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz".
*/
function alphabeticShift(inputString) {
let newStr = [];
@Nicknyr
Nicknyr / evenDigitsOnly.js
Created March 28, 2020 00:55
CodeSign - Even Digits Only
/*
Check if all digits of the given integer are even.
Example
For n = 248622, the output should be
evenDigitsOnly(n) = true;
For n = 642386, the output should be
evenDigitsOnly(n) = false
@Nicknyr
Nicknyr / evenDigitsOnly.js
Created March 28, 2020 00:55
CodeSign - Even Digits Only
/*
Check if all digits of the given integer are even.
Example
For n = 248622, the output should be
evenDigitsOnly(n) = true;
For n = 642386, the output should be
evenDigitsOnly(n) = false
@Nicknyr
Nicknyr / arrayReplace.js
Created March 27, 2020 23:06
CodeSignal - Array Replace
/*
Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem.
Example
For inputArray = [1, 2, 1], elemToReplace = 1, and substitutionElem = 3, the output should be
arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3].
*/
function arrayReplace(inputArray, elemToReplace, substitutionElem) {
@Nicknyr
Nicknyr / arrayMaximalAdjacentDifference.js
Created March 27, 2020 21:15
CodeSign - Maximal Adjacent Difference
/*
Given an array of integers, find the maximal absolute difference between any two of its adjacent elements.
Example
For inputArray = [2, 4, 1, 0], the output should be
arrayMaximalAdjacentDifference(inputArray) = 3.
*/
function arrayMaximalAdjacentDifference(inputArray) {