Skip to content

Instantly share code, notes, and snippets.

/**
* You can brute force and increment/decrement the given number until you find a valid-all-even-digits
* number, but the time complexity would be O(n) where n is value of the number. Instead, you
* can validate each digit starting with the highest power to come up with the nearest valid number.
* Since you can make a number even by going up or down, both paths have to be considered.
*
* For example, take 567;
*
* It won't matter what you do with '67' because '5' will always be invalid. So you have to make it even.
@hai5nguy
hai5nguy / flatten.js
Created February 12, 2019 17:31
hai nguyen - citrusbyte coding question
var sampleArray = [[1,2,3],[[4],[5,6], [7,[8],9]], [10, 11], [12, [13, 14]]]
function flatten(array) {
var result = [];
recurseFlatten(array, result);;
return result;
}
function recurseFlatten(array, result) {
for (var i = 0; i < array.length; i++) {
const arr = [10, 12]; // for simplicity, let's only have 2 runs
for (let i = 0; i < arr.length; i++) {
setTimeout(() => {
console.log('The index of this number is: ' + i);
}, 3000);
}
// ///////////////////////////////
// example with the let keyword
// ///////////////////////////////
// the following is how a computer will run the above for loop
const arr = [10, 12, 15, 21];
for (let i = 0; i < arr.length; i++) {
setTimeout(function() {
console.log('The index of this number is: ' + i);
}, 3000);
}
/////////////////////////////////
// example with the let keyword
/////////////////////////////////
// the following is how a computer will run the above for loop
const arr = [10, 12, 15, 21];
for (let i = 0; i < arr.length; i++) {
setTimeout(function() {
console.log('The index of this number is: ' + i);
}, 3000);
}
/////////////////////////////////
// example with the let keyword
/////////////////////////////////
// the following is how a computer will run the above for loop
import { dispatch } from '~/store/store'
import PadawanApi from '~/actions/padawan-api'
const create = async (student) => {
dispatch({
type: 'CREATE_STUDENT_START',
student
})
import { dispatch } from '~/store/store'
import PadawanApi from '~/actions/padawan-api'
const create = async (student) => {
dispatch({
type: 'CREATE_STUDENT_START',
student
})
shopt -s extglob
alias ll='ls -la'
alias redis='cd ~; redis-server /usr/local/etc/redis.conf'
alias ll_bower='ls -la bower_components'
# gits!
alias gfa="git fetch --all; gs"
# alias grh='git reset --hard; gl 10; gs'
@hai5nguy
hai5nguy / yo.js
Last active February 6, 2017 21:52
class Navigation extends React.Component {
constructor() {
super();
this.state = {
active: 'home',
};
}
changeNavigation = (e, section) => {
e.preventDefault();