This file contains 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
Element.prototype.getAncestorByClassName = function(className){ | |
var el = this; | |
while ((el = el.parentNode)) { | |
if(typeof el.className === "string" && el.className.match(className)) { | |
return el; | |
} | |
} | |
} | |
This file contains 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
## Ypdating Yarn repositories | |
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - | |
## Ypdating Yarn repositories | |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - | |
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list | |
## Updating apt with updated repositories | |
sudo apt-get update |
This file contains 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, { Suspense, lazy } from 'react'; | |
const DefaultSpinner = () => null; | |
export default (dynamicImport, Spinner) => { | |
const Component = lazy(dynamicImport); | |
return props => ( | |
<Suspense fallback={Spinner ? <Spinner /> : <DefaultSpinner />}> | |
<Component {...props} /> | |
</Suspense> |
This file contains 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'; | |
export default dynamicImport => | |
class MockAsyncComponent extends React.Component { | |
state = { Component: null }; | |
componentDidMount = () => dynamicImport.then(({ default: Component }) => this.setState({ Component })).error(error => null); | |
render = () => { | |
const { Component } = this.state; | |
console.error(Component); | |
return <Component {...this.props} />; |
This file contains 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
const handlePrintAfterCharRemoval = (result, char) => { | |
switch (result) { | |
case 'palindrome': return char; | |
case 'not possible': return result; | |
default : | |
if (result.length === 1) { | |
return `${result}${char}`; | |
} | |
return ''; // implies that function should continue to try other ways to check the plaindrome |
This file contains 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
function LongestIncreasingSequence(arrayOfNaturaNumbers) { | |
let lis = 1; | |
let lastNumber; | |
const totalNumbers = arrayOfNaturaNumbers.length; | |
let internalLoop = totalNumbers - 1; | |
const lisFound = lis > lis; | |
const sequenceRecords = []; | |
for (let index = 0; index < totalNumbers - 1 && !lisFound; index++) { | |
// if (index > 0) break; // testing | |
const currNumber = arrayOfNaturaNumbers[index]; |
This file contains 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 | |
// Complexity: O(n/2) | |
function isPalindrome($str) { | |
$array = str_split($str); | |
$arrayLen = sizeof($array) - 1; | |
foreach ($array as $index => $currChar) { | |
$indexFromBehind = $arrayLen - $index; | |
$charFromBehind = $array[$indexFromBehind]; | |
$charFromBehindLowerCase = strtolower($charFromBehind); | |
$currCharLowserCase = strtolower($currChar); |
This file contains 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 | |
function getLongestRepeatedString($array, $prevStartIndex = 0, $prevEndIndex = 0, $repeatOf = 2, $longestMatchFound = 0, $longestRepeatString = '') { | |
$matchCount = 0; | |
$startIndex; | |
$endIndex = $prevEndIndex ?: $repeatOf - 1; | |
$consecutiveMatchCount = 0; | |
$prevLongestRepeatString = $longestRepeatString; | |
if ($longestRepeatString) $longestRepeatString .= ', '; | |
// var_dump("========================="); |
This file contains 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 | |
function appearanceCount($str1len, $str2len, $str1, $str2) | |
{ | |
$matches = $chunk = $i = 0; | |
$str1len = strlen($str1); | |
$str2len = strlen($str2); | |
for($i; $i <= $str2len; $i++ ) { | |
if(isset($matched)) { | |
$chunk = $matched === 4 ? $chunk + 1 : $chunk + $matched; | |
} |
This file contains 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 | |
function getJumpAttempts($maxJump,$slipsBy,$wallHeights) | |
{ | |
$attempts = 0; | |
foreach($wallHeights as $wallHeight) { | |
$attempts++; | |
do { | |
if($wallHeight > $maxJump) { | |
$wallHeight -= $maxJump - $slipsBy; |
OlderNewer