Skip to content

Instantly share code, notes, and snippets.

View karuna24s's full-sized avatar

Karuna Sehgal karuna24s

View GitHub Profile
const array = [2, 5, 4, 3, 1];
function bubbleSort(array) {
let swapped;
do {
swapped = false;
for(let i = 0; i < array.length; i++) {
if(array[i] && array[i + 1] && array[i] > array[i + 1]) {
[array[i], array[i + 1]] = [array[i + 1], array[i]];
swapped = true;
// Create an array to sort
var array = [9, 2, 5, 6, 4, 3, 7, 10, 1, 12, 8, 11];
// Basic implementation (pivot is the first element of the array)
function quicksort(array) {
if (array.length == 0) return [];
var left = [], right = [], pivot = array[0];
for (var i = 1; i < array.length; i++) {
// Split the array into halves and merge them recursively
function mergeSort(array) {
if (array.length === 1) {
// Return once we hit an array with a single item
return array
}
// Get the middle item of the array rounded down by creating a variable
const middle = Math.floor(array.length / 2)
// Create a variable for the items on the left side
<!DOCTYPE html>
<html>
<head>
<title>Heart</title>
</head>
<body>
<div class='container'>
<div class='heart'></div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>CSS Animations</title>
</head>
<body>
<div class="small-square"></div>
<div class="square"></div>
<div class="balloon"><img src="http://www.pngpix.com/wp-content/uploads/2016/08/PNGPIX-COM-Hot-Air-Balloon-PNG-Transparent-Image.png"></div>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Bounce In</title>
</head>
<body>
<div><h1>Bounce In</h1></div>
<p>Example from <a href="https://robots.thoughtbot.com/css-animation-for-beginners">CSS Animation for Beginners by Rachel Cope</a>, December 04, 2014</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Bouncing Ball</title>
</head>
<body>
<div class="ball"></div>
<div class="shadow"></div>
</body>
</html>
class CommentsController < ApplicationController
before_action :set_destination
def create
@comment = current_user.comments.create(comment_params)
@comment.destination = @destination
@comment.save
redirect_to destination_path(@destination)
end
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
def after_sign_in_path_for(resource)
request.env['omniauth.origin'] || root_path
end
protected
class DestinationsController < ApplicationController
def index
@destinations = Destination.all
end
def show
@destination = Destination.find(params[:id])
@food = @destination.food
if current_user
@comment = current_user.comments.build(destination: @destination)