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
// Note: The time complexity of this solution is O(n) | |
function getMaxConsecutiveChar(str) { | |
let char = preChar = str[0]; | |
let occurrence = count = 1; | |
for(let i = 1; i < str.length; i++){ | |
if(preChar === str[i]) count++; | |
if(count > occurrence) { | |
occurrence = count; | |
char = preChar; | |
} |
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 capitalizeString(str = "") { | |
// Break name into word's chunk. | |
let words = str.split(' '); | |
// Removed empty string, null, undefined, etc. | |
let filteredWords = words.filter(word => word); | |
// Capatilize words. | |
let capatilizeWords = filteredWords.map(word => `${word[0].toUpperCase()}${word.slice(1)}`); | |
// Concatenate words. | |
return capatilizeWords.join(' '); | |
} |
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 persistence(num, count = 0){ | |
return num > 9 ? persistence(eval(`${num}`.split('').join('*')), count+1) : count; | |
} | |
persistence(39) === 3 // because 3*9 = 27, 2*7 = 14, 1*4=4 | |
// and 4 has only one digit | |
persistence(999) === 4 // because 9*9*9 = 729, 7*2*9 = 126, | |
// 1*2*6 = 12, and finally 1*2 = 2 |
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 axios from 'axios'; | |
const API_CLIENT = axios.create({ | |
baseURL: 'base_url/api/v1/' | |
}); | |
// request interceptor | |
const REQUEST_INTERCEPTOR = API_CLIENT.interceptors.request.use(function (config) { | |
// TODO: uncomment Authorization header when token is available. | |
// config.headers['Authorization'] = `Bearer ${localStorage.getItem('access_token')}`; |
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
sudo nohup npm start & |
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 climbingLeaderboard(scores, alice) { | |
const uniqueScores = [...new Set(scores)]; //for removing duplicate entries. | |
let preIndex = uniqueScores.length, //starting position of nested loop. | |
rank = uniqueScores.length + 1, //last rank default. | |
aliceRanks = []; | |
for(let i = 0; i < alice.length; i++){ | |
let s = preIndex; | |
for(s; s--;){ | |
if(alice[i] < uniqueScores[s]){ |
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
<link href='https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900' rel='stylesheet' type='text/css'> | |
<style> | |
* { | |
margin: 0; | |
padding: 0; | |
font-family: Lato; | |
} | |
body { | |
padding: 50px 0; | |
/*background: #e5e2e6;*/ |
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 palindrome(str) { | |
str = str.toLowerCase(); //convert to lowercase | |
let count = Math.ceil(str.length / 2), //limit for itration | |
flag = true; //palindrome or not | |
for(var i = 0; i < count; i++){ | |
//checking 0 and the last index are same or not | |
//if not same break | |
if(!(str[i] === str[str.length - i - 1])){ | |
flag = false; |
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
Blockchain (A distributed ledger organized in block) | |
ethereum (A blockchain application platform) | |
EVM (EVM is the runtime environment for smart contracts) | |
solidity (Solidity is contract-oriented, high-level programming language for writing smart contracts which run on Ethereum Virtual Machine.) | |
smartcontract (A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract.) | |
remix (Web browser based IDE that allows you to write Solidity smart contracts) | |
web3.js (Ethereum JavaScript API) | |
DApps (distributed app) | |
metamask (MetaMask is a bridge that allows you to visit the distributed app in your browser. | |
It allows you to run Ethereum dApps right in your browser without running a full Ethereum node.) |
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
db.getCollection('your collection').aggregate([ | |
{ | |
"$project": { | |
chapters: "$books.chapters", _id: "$_id" | |
} | |
}, | |
{ | |
"$unwind": "$chapters" | |
}, | |
{ |
NewerOlder