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
<html> | |
<head> | |
<script> | |
! function() { | |
var analytics = window.analytics = window.analytics || []; | |
if (!analytics.initialize) | |
if (analytics.invoked) window.console && console.error && console.error("Segment snippet included twice."); | |
else { | |
analytics.invoked = !0; |
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
function minusLastItem(array) { | |
// your code goes here | |
var minusLast = array.slice(0,array.length-1); | |
return minusLast; | |
} | |
function copyFirstHalf(array) { | |
// your code goes here |
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 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]; | |
} |
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
//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]; |
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 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); |
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 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++){ |
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
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) | |
{ |