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 / gist:077b2b827720ccd5e2867e64d252cc0b
Last active October 10, 2018 04:41
Javascript Palindrone Function - Iterative approach w/ for loops
function isPalindrone(word) {
let lettersCounter = 1;
for(let i = 0; i < word.length; i++) {
if(word[i] == word[word.length - lettersCounter]) {
lettersCounter++;
if (lettersCounter == word.length) {
return true;
}
}
@Nicknyr
Nicknyr / gist:17e84cc77b74e7dee351d7dfa298b83f
Last active October 10, 2018 04:41
Javascript Palindrone - Turn string into array and then use .reverse method to compare
function isPalindrone(word) {
// This approach converts the string into an array and then reverses it
// Split splits the string into an array, each letter of the word is it's own array element
// Reverse reverses the array elements but they are still separate characters spaced out
// Join squishes the letters back into be one solid word without spaces between characters
let reversed = word.split('').reverse().join('');
// Compare orginal word to reversed word
if( word == reversed) {
@Nicknyr
Nicknyr / example.js
Created August 10, 2019 20:56
React: Toggling elements onClick using state, an event handler, and conditional rendering
import React, { Component } from "react";
import styled, { css } from "styled-components";
const Styles = styled.div`
.red {
background: red;
height: 5em;
width: 5em;
display: inline-block;
margin: 1em;
/*
CodeSignal adjacentElementsProduct problem:
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
Example
For inputArray = [3, 6, -2, -5, 7, 3], the output should be
adjacentElementsProduct(inputArray) = 21.
/*
CodeSignal Add Two Digits Problem:
You are given a two-digit integer n. Return the sum of its digits.
Example
For n = 29, the output should be
addTwoDigits(n) = 11.
/*
CodeSignal: Given an integer n, return the largest number that contains exactly n digits.
Example
For n = 2, the output should be
largestNumber(n) = 99.
Input/Output
/*
CodeSignal Candies:
n children have got m pieces of candy. They want to eat as much candy as they can, but each child must eat exactly the same amount of candy as any other child. Determine how many pieces of candy will be eaten by all the children together. Individual pieces of candy cannot be split.
Example
For n = 3 and m = 10, the output should be
candies(n, m) = 9.
/*
Your friend advised you to see a new performance in the most popular theater in the city. He knows a lot about art and his advice is usually good, but not this time: the performance turned out to be awfully dull. It's so bad you want to sneak out, which is quite simple, especially since the exit is located right behind your row to the left. All you need to do is climb over your seat and make your way to the exit.
The main problem is your shyness: you're afraid that you'll end up blocking the view (even if only for a couple of seconds) of all the people who sit behind you and in your column or the columns to your left. To gain some courage, you decide to calculate the number of such people and see if you can possibly make it to the exit without disturbing too many people.
Given the total number of rows and columns in the theater (nRows and nCols, respectively), and the row and column you're sitting in, return the number of people who sit strictly behind you and in your column or to the left, assuming all
@Nicknyr
Nicknyr / maxMultiple.js
Created October 21, 2019 00:29
Code Signal - Max Multiple challenge
/*
Given a divisor and a bound, find the largest integer N such that:
N is divisible by divisor.
N is less than or equal to bound.
N is greater than 0.
It is guaranteed that such a number exists.
Example
@Nicknyr
Nicknyr / allLargestStrings.js
Created December 26, 2019 02:34
Code Signal - All Largest Strings challenge
/*
Given an array of strings, return another array containing all of its longest strings.
Example
For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be
allLongestStrings(inputArray) = ["aba", "vcd", "aba"].
*/