Skip to content

Instantly share code, notes, and snippets.

View lwebber's full-sized avatar
🎯
Focusing

Laura Webber lwebber

🎯
Focusing
View GitHub Profile
@lwebber
lwebber / isValidParentheses.js
Created December 3, 2016 08:02 — forked from anonymous/isValidParentheses.js
isValidParentheses created by wwebby1 - https://repl.it/EcdZ/1
function validParentheses(parens){
if(parens[0] == ")")
return false;
if(parens[parens.length-1] == "(")
return false;
for(var i = 0; i < parens.length-1; i++)
{
if(parens[i]=="(" && parens.length%2 == 0)
{
@lwebber
lwebber / Scramble String.js
Created December 3, 2016 08:05 — forked from anonymous/Scramble String.js
Scramble String created by wwebby1 - https://repl.it/E8r2/3
// Write a method that takes in a string and an array of indices in the
// string. Produce a new string, which contains letters from the input
// string in the order specified by the indices of the array of indices.
//
function scramble(str, indices){
var result = [];
for(var i = 0; i < str.length; i++){
@lwebber
lwebber / is Power of Two.js
Created December 3, 2016 08:07 — forked from anonymous/is Power of Two.js
is Power of Two created by wwebby1 - https://repl.it/E87A/2
// # Write a method that takes in a number and returns true if it is a
// # power of 2. Otherwise, return false.
// #
// # You may want to use the `%` modulo operation. `5 % 2` returns the
// # remainder when dividing 5 by 2; therefore, `5 % 2 == 1`. In the case
// # of `6 % 2`, since 2 evenly divides 6 with no remainder, `6 % 2 == 0`.
// #
function isPowerOf2(num){
var base = Math.log2(num);
@lwebber
lwebber / ArithGeo.js
Created December 3, 2016 08:09 — forked from anonymous/ArithGeo.js
ArithGeo created by wwebby1 - https://repl.it/E5tx/2
//check if a sequence follows an arithmetic or geometric pattern. return -1 if neither
function ArithGeo(arr) {
var arithchecker = false;
var geochecker = false;
for(var i = 1; i < arr.length; i++)
{
var diff1 = arr[i] - arr[i-1];
var diff2 = arr[i+1] - arr[i];
@lwebber
lwebber / Third Greatest with Sort(compare).js
Created December 3, 2016 08:11 — forked from anonymous/Third Greatest with Sort(compare).js
Third Greatest with Sort(compare) created by wwebby1 - https://repl.it/E876/3
// # Write a method that takes an array of numbers in. Your method should
// # return the third greatest number in the array. You may assume that
// # the array has at least three numbers in it.
// #
function thirdGreatest(nums){
nums.sort(function compare(num1, num2)
{return num1 -num2});
return nums[nums.length-3];
}
@lwebber
lwebber / Array Copy II.js
Created August 25, 2017 21:52 — forked from anonymous/Array Copy II.js
Array Copy II created by wwebby1 - https://repl.it/G9G7/30
function minusLastItem(array) {
// your code goes here
var minusLast = array.slice(0,array.length-1);
return minusLast;
}
function copyFirstHalf(array) {
// your code goes here
@lwebber
lwebber / JSNumDrills.txt
Created September 17, 2019 03:38
JS Number Drills
https://repl.it/@wwebby1/area-of-a-rectangle-drill
https://repl.it/@wwebby1/temperature-conversion-drill
https://repl.it/@wwebby1/Is-divisible-drill-1
Traffic Lights drill
https://repl.it/@wwebby1/Traffic-lights-drill
Error Alert Drill
https://repl.it/@wwebby1/Error-alert-drill
https://repl.it/@wwebby1/Creating-arrays-drill-1
https://repl.it/@wwebby1/Adding-array-items-drills
https://repl.it/@wwebby1/Accessing-array-items-drill
https://repl.it/@wwebby1/Array-length-and-access-drill
https://repl.it/@wwebby1/Array-copying-I-drill
Copying II Drill (Repl.it broken)
function minusLastItem(array) {
return array.slice(0, array.length-1)
}
Max & Min Drill
function max(numbers) {
let max = numbers[0];
for (let i = 1; i < numbers.length; i++) {
if(numbers[i] > max)
max = numbers[i];
}
return max;
}