Skip to content

Instantly share code, notes, and snippets.

View AnielaMW's full-sized avatar
☺️
Looking for my next challenge.

A. Wolkonowski AnielaMW

☺️
Looking for my next challenge.
  • RedArgyle
  • Upstate New York
View GitHub Profile
@AnielaMW
AnielaMW / captcha.rb
Last active March 2, 2018 23:04
Captcha 3 Ways
require 'pry'
num1 = 1122 #=> 3
num2 = 8182759778 #=>15
num3 = 12345 #=>0
def captcha1(num)
list = num.to_s.split('').map(&:to_i)
total = 0
import React, { Component } from 'react';
import StepTile from '../components/StepTile';
import ItemTile from '../components/ItemTile';
import FetchButton from '../components/FetchButton';
class InstructionsContainer
extends Component {
constructor(props) {
super(props);
this.state = {
@AnielaMW
AnielaMW / App.js
Created March 10, 2018 05:21
React Marathon - Launch Academy
import React from 'react';
import PlaylistCollection from './PlaylistCollection';
import SongCollection from './SongCollection';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedPlaylistId: props.data.selectedPlaylistId
};
@AnielaMW
AnielaMW / first_duplicate.rb
Created March 14, 2018 15:18
First Duplicate Challenge
require 'pry'
def first_duplicate1(a)
counts = []
a.each_with_index do |value, i|
return value if counts[value]
counts[value] = true
binding.pry
end
-1
@AnielaMW
AnielaMW / stair_challenge.rb
Created February 12, 2019 00:35
Stairs Challenge_Ruby
puts "Stairs Challenge"
# Given
# x = the number of steps to the top of a stair
# and
# n = is the maximum stride to be taken
# Solve for the total number of ways to reach the top step.
# Assumptions
# There will always be at least one way.
# 0 is not a valid stride.
@AnielaMW
AnielaMW / merge_sort.rb
Last active July 19, 2019 06:26
Merge Sort-Ruby
require 'pry'
puts "Merge Sort"
# 1. Check the input array length. If it is 0 or 1, return the array (already sorted!)
# 2. If array length is greater than 1, then we want to define a mid-point, picked by choosing array.length / 2 and call a floor method so the number always rounds down.
# 3. Use the midpoint to divide the array into halves, a left and right. I set my left array to start with first element and end at element mid — 1. My right array starts at mid and ends at the last element. (Note: Ruby ranges .. are inclusive of the last element, whereas ... are exclusive of last element).
# 4. Note that not only do I set left and right subarrays equal to the lengths above, but they’re set to the merge_sort version of those subarrays. That means that merge_sort will be called upon these subarrays, which means picking a new midpoint, dividing the subarray into halves, and set left and right subarrays that will call merge_sort again.
# 5. Lastly, I have a call to the merge method to combine the left and right
@AnielaMW
AnielaMW / quick_sort.rb
Last active March 6, 2019 22:25
Quick Sort Challenge in Ruby
require 'pry'
puts "Quick Sort"
# 1. First, our checks to see if array.length <= 1.
# 2. Pick a pivot at random. Ruby’s delete_at method will delete the item at the specified index, which in this case would be a rand index in the range of array.length. We’re saving the value of that item to pivot.
# 3. Create a new left and right subarray.
# 4. Loop through every element in the array and compare it to the pivot. If the value is less than pivot, add element to the left subarray. If value is greater than pivot, add element to the right subarray.
def quick_sort(arr)
return arr if arr.length <= 1
@AnielaMW
AnielaMW / bubble_sort.rb
Last active March 6, 2019 21:21
Bubble Sort Challenge
require 'pry'
puts "Bubble Sort"
# 1. bubble_sort takes in a single array parameter.
# 2. If the array size is 1 or 0, return the array; by default,
# an empty array or array with one element is sorted.
# 3. Create the swap variable and set it to true by default.
# 4. Create a while loop that will run as long as swap is true.
# 5. Set swap = false since immediately after the beginning of your loop,
# there have been no swaps.
@AnielaMW
AnielaMW / insertion_sort.rb
Last active March 6, 2019 21:45
Insertion Sort Challenge
require 'pry'
puts "Insertion Sort"
# 1. First, we iterate through all elements of the array with (array.length).times do. j represents the index of the item in the array.
# 2. Then we set the if/else checks to run only if j > 0 (element is not the first item, which has index 0).
# 3. The if/else checks compares the previous element with the current element; if previous element is larger than current element, swap previous with current.
# 4. If previous element is not larger than current element, the if/else terminates.
# 5. The j counter is decremented by 1.
@AnielaMW
AnielaMW / selection_sort.rb
Last active March 6, 2019 22:13
Selection Sort Challenge
require 'pry'
puts "Selection Sort"
# 1. Set n equal to array.length — 1: this represents how many times you need to do the comparisons. Loop though n.times.
# 2. Set a min_index value equal to your initial i index (should be the first element in array).
# 3. Create a second (nested) loop starting at the second element until n using variable j.
# 4. Compare the value of element at index j with value of element of min_index. If value of element at index j is less than value of element of min_index, index j becomes the new min_index. Set min_index = j if this is the case. Exit the inner loop.
# 5. If value of new min_index is not equal to value of element at i then swap value of element at i index with value of element at min_index.
# 6. Lastly, return the manipulated array.