Skip to content

Instantly share code, notes, and snippets.

View kdnk's full-sized avatar
💭
🚀

Kodai Nakamura kdnk

💭
🚀
View GitHub Profile

変数

  • val: 変更不可.valueの略.
  • var: 変更可.variableの略.

型の宣言

Scalaは型推論してくれる.

Common.js

モジュールの作成

module.export = mymodule
// または
export.mymodule

モジュールの呼び出し

# tmux update from 1.8 to 2.0 on ubuntu 14.04
tmux -V
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository -y ppa:pi-rho/dev
sudo apt-get update
sudo apt-get install -y tmux=2.0-1~ppa1~t
tmux -V
@kdnk
kdnk / hoisting.js
Last active November 4, 2016 14:50
var scope = "global"
function fn () {
console.log(scope)
var scope = "local"
console.log(scope)
}
function fn2 () {
console.log(scope)
// JavaScript O'reilly
// スコープチェーン
// 関数が定義されたときに、現在有効なスコープチェーンを保存しておく。
// 関数が呼び出されたときに、新たにオブジェクトを生成し、ローカル変数を保存。
// 新たに生成されたオブジェクトをスコープチェーンに追加し、新たなスコープチェーンを生成。
// 入れ子の場合は、外側の関数が呼び出されるたびに内側の関数が再び定義される。
// そのため、外側の関数の呼び出しごとに、スコープチェーンがことなる。
var scope = 'global'
@kdnk
kdnk / async_practice.js
Created November 12, 2016 08:52
async/await
async function main () {
const user = await getUser('kodai', 'nakamura')
const email = await getEmail(user)
return email
}
main()
.then(email => {
console.log(email)
})
@kdnk
kdnk / quick_sort.js
Last active November 28, 2016 13:46
main()
function main () {
let arr = [5, 8, 4, 2, 6, 1, 3, 9]
console.log('original: ')
printArray(arr)
quickSort(arr, 0, arr.length - 1)
}
function swap (a, idx1, idx2) {
@kdnk
kdnk / buble_sort.js
Last active November 28, 2016 14:37
main()
function main () {
let arr = [5, 8, 4, 2, 6, 1, 3, 9]
printArray(arr)
bubleSort(arr, arr.length)
printArray(arr)
}
function swap (a, idx1, idx2) {
main()
function main () {
let arr = [5, 8, 4, 2, 6, 1, 3, 9]
printArray(arr)
straightSelectionSort(arr, arr.length)
printArray(arr)
}
function straightSelectionSort (a, n) {
main()
function main () {
let a = [5, 7, 15, 28, 29, 31, 39, 58, 68, 70, 95]
const key = 39
const index = binarySearch(a, a.length - 1, key)
console.log('index ', index)
}
function binarySearch (a, n, key) {