2024-03-29から1日間の記事一覧

google colabolatory⑪ JavaScriptでアルゴリズム([ソート編①]バブルソート)

ソートのアルゴリズムもやってみます。 まずはバブルソートです。 %%js //バブルソートで昇順に並べかえる const data = [8,5,2,4,7,3,1,9]; let arr = [...data]; function swap(array, idx1, idx2){ let tmp = array[idx1]; array[idx1] = array[idx2]; ar…

google colabolatory⑩ JavaScriptでアルゴリズム(配列の要素を反転する)

ついでなので、配列の要素を反転する方法も学習してみます。 %%js const data = [1,2,3,4,5,6,7,8,9]; let arr = [...data]; function swap(array, idx1, idx2){ let tmp = array[idx1]; array[idx1] = array[idx2]; array[idx2] = tmp; } function reverse(…