This file contains hidden or 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
| // • • • Empty an array in JavaScript • • • // | |
| // • original array's value will be changed • // | |
| // bold aaproach: arr = []; | |
| // the return value of .splice will be an array containing the deleted elements. | |
| var arr = [1, 3, 5, 7]; | |
| arr.splice(0, arr.length); | |
| arr; // [] | |
This file contains hidden or 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
| This is a test for the Github API gist POST ajax call. |
This file contains hidden or 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
| # create a new folder under public for each user | |
| user_id = gif.user_id | |
| gif_file_name = params[:gif][:filename] | |
| gif_file = params[:gif][:tempfile] | |
| File.open("./public/users/#{user_id}/#{gif_file_name}", 'w') do |f| | |
| f.write(gif_file.read) | |
| end |
This file contains hidden or 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
| def mergesort(list) | |
| return list if list.size <= 1 | |
| mid = list.size / 2 | |
| left = list[0, mid] | |
| right = list[mid, list.size] | |
| merge(mergesort(left), mergesort(right)) | |
| end | |
| def merge(left, right) | |
| sorted = [] |
This file contains hidden or 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
| def bubble_sort(array) | |
| n = array.length | |
| loop do | |
| swapped = false | |
| (n-1).times do |i| | |
| if array[i] > array[i+1] | |
| array[i], array[i+1] = array[i+1], array[i] | |
| swapped = true | |
| end | |
| end |