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
constructor(props) { | |
super(props); | |
this.state = { skin: 'night' }; | |
this.changeSkin = this.changeSkin.bind(this); | |
} |
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
<p onClick={this.changeSkin} style={{ fontSize: '50px', cursor: 'pointer' }}>Change Skin</p> |
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
<div className={this.state.skin}> |
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
import React, { Component } from 'react'; | |
import './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { skin: 'night' }; | |
this.changeSkin = this.changeSkin.bind(this); | |
} | |
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
import React from 'react'; | |
import $ from 'jquery'; |
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
arr1 = [1, 2, 3, 9]; | |
arr2 = [1, 2, 4, 4]; | |
// Method 1 | |
// Time Complexity: O(N^2) | |
// Space Complexity: O(1) | |
const findSum = (arr, val) => { | |
for (let i = 0; i < arr.length; i++) { | |
for (let j = 0; j < arr.length; j++) { |
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
// https://tc39.github.io/ecma262/#sec-array.prototype.includes | |
if (!Array.prototype.includes) { | |
Object.defineProperty(Array.prototype, 'includes', { | |
value: function(valueToFind, fromIndex) { | |
if (this == null) { | |
throw new TypeError('"this" is null or not defined'); | |
} | |
// 1. Let O be ? ToObject(this value). |
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
<?php // Register Custom Post Type: Movies | |
function movies_post_type() { | |
$labels = array( | |
'name' => _x( 'Movies', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'Movie', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Movies', 'text_domain' ), | |
'name_admin_bar' => __( 'Movie', 'text_domain' ), | |
'archives' => __( 'Item Archives', 'text_domain' ), |
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
<?php // Add Custom Field Type: Genre | |
function genre_meta_box() { | |
add_meta_box( | |
'global-notice', | |
__( 'Genre', 'sitepoint' ), | |
'genre_meta_box_callback', | |
'movies', | |
'side', | |
'low' |
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
<?php // Register a Custom Field Type as a REST field | |
function register_genre_as_rest_field() { | |
register_rest_field( | |
'movies', | |
'genre', | |
array( | |
'get_callback' => 'get_genre_meta_field', | |
'update_callback' => null, | |
'schema' => null, |