Skip to content

Instantly share code, notes, and snippets.

Nick Kinlen Nicknyr

  • NYC
Block or report user

Report or block Nicknyr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Nicknyr
Nicknyr / gist:17e84cc77b74e7dee351d7dfa298b83f
Last active Oct 10, 2018
Javascript Palindrone - Turn string into array and then use .reverse method to compare
View gist:17e84cc77b74e7dee351d7dfa298b83f
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 / gist:077b2b827720ccd5e2867e64d252cc0b
Last active Oct 10, 2018
Javascript Palindrone Function - Iterative approach w/ for loops
View gist:077b2b827720ccd5e2867e64d252cc0b
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:9c8fc56a41ea6b5bcb623530b3e8aa27
Created Sep 30, 2018
Iterate through 2D array in React
View gist:9c8fc56a41ea6b5bcb623530b3e8aa27
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
constructor(props) {
super(props);
this.state = {
data: [[1,1,0,1,1,1],[1,1,1]]
@Nicknyr
Nicknyr / gist:3154be7f02e388653063aeb644431819
Created Aug 11, 2018
React pass state to child component as a prop - FreeCodeCamp example
View gist:3154be7f02e388653063aeb644431819
class MyApp extends React.Component {
constructor(props) {
super(props);
this.state = {
name: 'CamperBot'
}
}
render() {
return (
<div>
View gist:e9acbf59ab99d2c9e0fea00a5464cc93
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="spaceship_launch_illustration"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1400px" height="980px"
viewBox="0 0 1400 980" enable-background="new 0 0 1400 980" xml:space="preserve">
<g id="background">
<rect fill="#4A626E" width="1400" height="980"/>
<g>
<path fill="#405059" d="M1196.4,552.4C1196.4,278.2,974.1,56,700,56S203.6,278.2,203.6,552.4c0,182.1,98.1,341.3,244.3,427.6
h504.2C1098.3,893.6,1196.4,734.5,1196.4,552.4z"/>
View gist:689a8923e2637865486cfc6775b53d53
import React, { Component } from 'react';
import './App.css';
export default class ToDoList extends Component {
constructor(props) {
super(props);
this.state = {
userInput: '',
list: []
@Nicknyr
Nicknyr / gist:f644e25dd5f84aaa3d6a2bfe1bf01d1e
Created Dec 17, 2017
Updating state in React with a form input box example
View gist:f644e25dd5f84aaa3d6a2bfe1bf01d1e
import React, { Component } from 'react';
import './App.css';
export default class ToDoList extends Component {
constructor(props) {
super(props);
this.state = {
userInput: '',
list: []
@Nicknyr
Nicknyr / gist:1b90c37679b627d312a30b6a3e37973e
Last active Dec 6, 2017
Using Axios to make an AJAX request in React (uses Reddit API as an example)
View gist:1b90c37679b627d312a30b6a3e37973e
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import axios from "axios";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
posts: []
@Nicknyr
Nicknyr / Compare arrays
Last active Dec 9, 2017
Javascript: Use .every() function to compare two arrays and determine if they have the same elements in the same order
View Compare arrays
// Compare two arrays and determine if they have the same values in the same order
var compare = arr1.length == arr2.length &&
arr1.every(function(element, index){
return element == arr2[index];
});
if(compare) {
// Arrays match, do this
}
@Nicknyr
Nicknyr / Javascript Sounds
Last active Nov 1, 2017
Javascript: Function that uses Audio() to play a sound
View Javascript Sounds
// Uses Audio() to play an mp3
function sound() {
var audio = new Audio();
audio.src = "url to mp3";
audio.play();
}
You can’t perform that action at this time.