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. Return the longest word in | |
// the string. You may assume that the string contains only letters and | |
// spaces. | |
// | |
// You may use the String `split` method to aid you in your quest. | |
// | |
// Difficulty: easy. | |
function longest_word(sentence) { | |
var phrase=sentence.split(" ") |
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 that takes an integer `n` in; it should return | |
// n*(n-1)*(n-2)*...*2*1. Assume n >= 0. | |
// | |
// As a special case, `factorial(0) == 1`. | |
// | |
// Difficulty: easy. | |
function factorial(n) { | |
var fact=1 | |
if(n==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
// Write a function that will take a string as input, and return a new | |
// string with the same letters in reverse order. | |
// | |
// | |
// Difficulty: easy. | |
function reverse(string) { | |
var reversed="" | |
for(var i=string.length-1;i>=0;i--) | |
{ |
NewerOlder