Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
mmloveaa / My solutions to Loops challenge
Last active December 27, 2015 19:15
My solutions to Loops challenge
// 12/21/2015
//Use a while loop, a for loop, and a forEach loop to find the largest number in an array.
//Use the following array for each of these loops.
//[1,5,2,9,6,3]
----------------------------------------------------------------------------------------------------
//My while loop solution:
var max=0;
var i=0;
@mmloveaa
mmloveaa / Solutions using .reduce() .map() .filter() .sort()
Last active December 27, 2015 19:15
Solutions using .reduce() .map() .filter() .sort()
// 12/21/2015
// .reduce() method
function product(array){
var answer=array.reduce(function(a,b){
return a*b
})
return answer
}
@mmloveaa
mmloveaa / Factorial using recursion
Last active December 27, 2015 19:16
Factorial using recursion
// 12/21/2015
//This program runs well but we need to make it more elegant.
// Try to rewrite the code of the function factorial in way to use recursion.
// You can not use looping(for, while, forEach).
// Return examples
// factorial(3)=>3 x 2 x 1 = 6
// factorial(2)=>2 x 1 = 2
// factorial(0)=>1 = 1
// My Solution:
@mmloveaa
mmloveaa / Friends or Foes?
Last active December 27, 2015 19:16
Friends or Foes?
// 12/22/2015
// Make a program that filters a list of strings and returns a list
// with only your friends name in it. All your friends only have
// four letter in their name.
// Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"],
// Output = ["Ryan", "Yous"]
// My Solution:
@mmloveaa
mmloveaa / Arithmetic Sequence Sum
Last active December 27, 2015 19:17
Arithmetic Sequence Sum
// 12/22/2015
// In Your class You have started lessons about Arithmetic Progression.
// Because You are also a programmer, You have decided to write
// a function arithmetic_sequence_sum(a, r, n), that will print
// SUM of the first n elementh of the sequence with the given
// constant r and first elementh a
// For example arithmetic_sequence_sum(2, 3, 5)
// Should return: 40
@mmloveaa
mmloveaa / Find unique items of an array
Last active December 27, 2015 19:17
Find unique items of an array
// 12/22/2015
// Write a function uniq that takes in an array arr then returns
// unique items of arr.
// For example
// uniq(['a', 'b', 'a']) === ['a', 'b']
// My Solution:
@mmloveaa
mmloveaa / Multiples of 3 and 5
Last active December 27, 2015 19:18
Multiples of 3 and 5
// 12/22/2015
// Multiples of 3 and 5
// If we list all the natural numbers below 10 that are multiples
// of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
// Find the sum of all the multiples of 3 or 5 below 1000.
// My Solution:
@mmloveaa
mmloveaa / Find the next perfect square
Last active February 3, 2024 07:36
Find the next perfect square
// 12/22/2015
// You might know some pretty large perfect squares. But what about the NEXT one?
// Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that
an integral perfect square is an integer n such that sqrt(n) is also an integer.
// If the parameter is itself not a perfect square, than -1 should be returned. You may assume the parameter is positive.
// Examples:
// findNextSquare(121) --> returns 144
// findNextSquare(625) --> returns 676
@mmloveaa
mmloveaa / We Have Liftoff
Last active December 27, 2015 19:14
We Have Liftoff
// 12/22/2015
// You have an array of numbers 1 through 10 (JS: 1 through 10 or less). The array needs to be formatted correctly for the person
reading the countdown of a spaceship launch.
// Unfortunately, the person reading the countdown only knows how to read strings. After the array is sorted correctly make
sure it's in a format he can understand.
// Between each number should be a space and after the final number (1) should be the word 'liftoff!'
// Example:
// Given
@mmloveaa
mmloveaa / Email Validation
Last active December 27, 2015 19:13
Email Validation
// 12/23/2015
// Write a function to test whether a given input is a valid email address.
// For the purposes of this kata, here is what makes a valid email:
// At least one letter character at the beginning >>>>>
// All characters between the first character and the @ (if any)
// must be letters, numbers, or underscores >>>>>
// There must be an @ character (after the points listed just now) >>>>>
// After the @ character, there must be at least one word character (letter,