You will need to check the versions (last updated 8-8-18)
This file contains 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
# find the smalledst number in a given array of numbers | |
# then MOVE that number to the front of the array | |
# return the that same array | |
#RSpec | |
describe 'smallest_number_move_to_the_front' do | |
let(:numbers) { [24,6,8,3,234,6,7,65] } | |
let(:numbers2) { [24,6,8,234,6,7,65,734,-1,322,324,43213] } | |
it "method is defined" do |
This file contains 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
# given an array of numbers find the smallest number. | |
# return the same array with the lowest number at the front | |
#RSpec | |
describe 'smallest_number_move_to_the_front' do | |
let(:numbers) { [24,6,8,3,234,6,7,65] } | |
let(:numbers2) { [24,6,8,234,6,7,65,734,-1,322,324,43213] } | |
it "method is defined" do | |
expect(defined? smallest_number_move_to_the_front).to eq 'method' |
This file contains 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
# Hello Marc, so I just couldn't let our challenge go. after I left I kept thinking | |
# about the solution that I provided and the fact that it wouldn't work. So tonight | |
# I decided to code it and write some test for it and I wanted to share it with you. | |
# If I copied the array and then deleted the elements the program would always return 0 | |
# because that is where the duplicate number would live at the time it got compaired. | |
# I would love some feedback and would also love to see how you might solve this. | |
def find_duplicate_retrun_index(arr) | |
arrCopy = arr | |
arr.each_with_index do |value1, index1| |
This file contains 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
// Write a function charFreq() that takes a string and builds a frequency listing of the characters contained in it. | |
// Represent the frequency listing as a Javascript object. | |
// Try it with something like charFreq("abbabcbdbabdbdbabababcbcbab"). | |
// I got a lot help from stack on this one. I had no idea how to make a object from a string. | |
// and in doing research for that I found a solution to something similar to this. But I do understand | |
// how every line of code works and why! | |
function charFreq(source) { | |
var frequency = {}; |
This file contains 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
// Write a function filterLongWords() that takes an array of words and an integer i and returns the array of words | |
// that are longer than i. (if I understand what they are asking for).. | |
// also, why when I use << - this syntax doesn't work but the .push does?? I thought they both would work? | |
var i = 5 | |
var wordsGreaterThan = [] | |
function filterLongWords(source) { | |
var sentence = source.split(/\s/); | |
for ( var j = 0; j < sentence.length; j++) { |
This file contains 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
// Write a function findLongestWord() that takes an array of words and returns the length of the longest one. | |
// woops, didn't read it.... I took a phase turned it into a array... | |
var longestWord = ""; | |
function findLongestWord(phase) { | |
var sentence = phase.split(/\s/); | |
for ( var i = 0; i < sentence.length; i++ ) { | |
if (sentence[i].length > longestWord.length) { | |
longestWord = longestWord.replace(longestWord, sentence[i]); |
This file contains 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
// Represent a small bilingual lexicon as a Javascript object in the following fashion {"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"} and use it to translate your Christmas cards from English into Swedish. | |
var greetings = { | |
"merry": "god", | |
"christmas": "jul", | |
"and": "och", | |
"happy": "gott", | |
"new": "nytt", | |
"year": "ar" | |
}; |
This file contains 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
// Sure seems like a lot of code just to reverse a string! | |
// Define a function reverse() that computes the reversal of a string. For example, reverse("jag testar") | |
// should return the string "ratset gaj". | |
var new_str = "" | |
function reverse(string) { | |
for (var i = string.length - 1; i >= 0; i--) { | |
new_str += string[i]; | |
} | |
return new_str; | |
} |
This file contains 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
// Write a function translate() that will translate a text into "rövarspråket". | |
// That is, double every consonant and place an occurrence of "o" in between. | |
// For example, translate("this is fun") should return the string "tothohisos isos fofunon". | |
var character = [] | |
function translate(sentence) { | |
var new_str = sentence.split(""); | |
for (var i = 0; i < new_str.length; i++) { |
NewerOlder