diff --git a/completed_exercises/1-reverse-int.js b/completed_exercises/1-reverse-int.js deleted file mode 100644 index 9ccf1c4..0000000 --- a/completed_exercises/1-reverse-int.js +++ /dev/null @@ -1,16 +0,0 @@ -// --- Directions -// Given an integer, return an integer that is the reverse -// ordering of numbers. -// --- Examples -// reverseInt(15) === 51 -// reverseInt(981) === 189 -// reverseInt(500) === 5 -// reverseInt(-15) === -51 -// reverseInt(-90) === -9 - -function reverseInt(n) { - const reversed = n.toString().split('').reverse().join('') - return parseInt(reversed) * Math.sign(n) -} - -console.log(reverseInt(-15)); \ No newline at end of file diff --git a/completed_exercises/1-reverse-string.js b/completed_exercises/1-reverse-string.js deleted file mode 100644 index 5c82fed..0000000 --- a/completed_exercises/1-reverse-string.js +++ /dev/null @@ -1,25 +0,0 @@ -// --- Directions -// Given a string, return a new string with the reversed order of characters -// --- Examples -// reverse('hi') === 'ih' -// reverse('hello') === 'olleh' -// reverse('CodingMoney') === 'yenoMgnidoC' - -function reverse(str) { - - return str.split('').reverse().join('') - -} - -console.log(reverse('CodingMoney')); - - -// function reverse(str) { -// let reversed = '' - -// for(let char of str){ -// reversed = char + reversed -// } - -// return reversed -// } \ No newline at end of file diff --git a/completed_exercises/10-fizzbuzz.js b/completed_exercises/10-fizzbuzz.js deleted file mode 100644 index c8ac0a7..0000000 --- a/completed_exercises/10-fizzbuzz.js +++ /dev/null @@ -1,29 +0,0 @@ -// --- Directions -// Write a program that console logs the numbers -// from 1 to n. But for multiples of three print -// “fizz” instead of the number and for the multiples -// of five print “buzz”. For numbers which are multiples -// of both three and five print “fizzbuzz”. -// --- Example -// fizzBuzz(5); -// 1 -// 2 -// fizz -// 4 -// buzz - -function fizzBuzz(n) { - for(let i=1; i<=n; i++){ - if(i % 3 === 0 && i % 5 === 0){ - console.log('fizzbuzz') - }else if( i % 3 === 0 ){ - console.log('fizz') - }else if( i % 5 === 0){ - console.log('buzz') - }else{ - console.log(i) - } - } -} - -fizzBuzz(20) \ No newline at end of file diff --git a/completed_exercises/11-the-matrix.js b/completed_exercises/11-the-matrix.js deleted file mode 100644 index 58bf3fe..0000000 --- a/completed_exercises/11-the-matrix.js +++ /dev/null @@ -1,57 +0,0 @@ -// --- Directions -// Write a function that accepts an integer N -// and returns a NxN spiral matrix. -// --- Examples -// matrix(2) -// [[1, 2], -// [4, 3]] -// matrix(3) -// [[1, 2, 3], -// [8, 9, 4], -// [7, 6, 5]] -// matrix(4) -// [[1, 2, 3, 4], -// [12, 13, 14, 5], -// [11, 16, 15, 6], -// [10, 9, 8, 7]] - -function matrix(n) { - const result = [] - let counter=1, startRow=0, endRow=n-1, startCol=0, endCol=n-1 - for(let i=0; i=startCol; i--){ - result[endRow][i] = counter - counter++ - } - endRow-- - //Left - for(let i=endRow; i>=startRow; i--){ - result[i][startCol] = counter - counter++ - } - startCol++ - } - - return result -} - -console.log(matrix(6)); diff --git a/completed_exercises/2-palindrome.js b/completed_exercises/2-palindrome.js deleted file mode 100644 index e6dee7f..0000000 --- a/completed_exercises/2-palindrome.js +++ /dev/null @@ -1,18 +0,0 @@ -// --- Directions -// Given a string, return true if the string is a palindrome -// or false if it is not. Palindromes are strings that -// form the same word if it is reversed. - -// --- Examples: -// palindrome("kayak") === true -// palindrome("madam") === true -// palindrome("codingmoney") === false //yenomgnidoc - -function palindrome(str) { - const reversed = str.split('').reverse().join('') - - return str === reversed - -} - -console.log(palindrome('codingmoney')); \ No newline at end of file diff --git a/completed_exercises/3-maxchars.js b/completed_exercises/3-maxchars.js deleted file mode 100644 index 578007e..0000000 --- a/completed_exercises/3-maxchars.js +++ /dev/null @@ -1,27 +0,0 @@ -// --- Directions -// Given a string, return the character that is most -// commonly used in the string. -// --- Examples -// maxChar("abcccccccd") === "c" -// maxChar("apple 1231111") === "1" - -function maxChar(str) { - const charMap = {} - let max = 0 - let maxChar = '' - for(let char of str){ - charMap[char] = ++charMap[char] || 1 - } - - for(let key in charMap){ - if(charMap[key] > max){ - max = charMap[key] - maxChar = key - } - } - - return maxChar -} - -console.log(maxChar("apple 1231111")); - diff --git a/completed_exercises/4-array-chunking.js b/completed_exercises/4-array-chunking.js deleted file mode 100644 index df5ed61..0000000 --- a/completed_exercises/4-array-chunking.js +++ /dev/null @@ -1,22 +0,0 @@ -// --- Directions -// Given an array and chunk size, divide the array into many subarrays -// where each subarray is of length size -// --- Examples -// chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]] -// chunk([1, 2, 3, 4, 5], 2) --> [[ 1, 2], [3, 4], [5]] -// chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) --> [[ 1, 2, 3], [4, 5, 6], [7, 8]] -// chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]] -// chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]] - -function chunk(array, size) { - const result = [] - let index = 0 - while(index 'This Is Mukhtar From Coding Money' -// capitalize('what is titlecase?') --> 'What Is Titlecase?' -// capitalize('titles of books, movies, songs, plays and other works') --> 'Titles Of Books, Movies, Songs, Plays And Other Works' - -function capitalize(str) { - const words = str.split(' ') - //['this', 'is', 'mukhtar'..] - - - return words.map(word => word[0].toUpperCase() + word.slice(1)).join(' ') - -} - - -console.log(capitalize('this is mukhtar from coding money')); \ No newline at end of file diff --git a/completed_exercises/6-anagrams.js b/completed_exercises/6-anagrams.js deleted file mode 100644 index e413721..0000000 --- a/completed_exercises/6-anagrams.js +++ /dev/null @@ -1,49 +0,0 @@ -// --- Directions -// Check to see if two provided strings are anagrams of eachother. -// One string is an anagram of another if it uses the same characters -// in the same quantity. Only consider characters, not spaces -// or punctuation. Consider capital letters to be the same as lower case -// --- Examples -// anagrams('coding money', 'money coding') --> True -// anagrams('RAIL! SAFETY!', 'fairy tales') --> True -// anagrams('Hi there', 'Bye there') --> False - -function cleanStr(str){ - return str.toLowerCase().replace(/[\W]/g,'').split('').sort().join('') -} -function anagrams(stringA, stringB) { - - return cleanStr(stringA) === cleanStr(stringB) - -} - - -console.log(anagrams('RAIL! SAFETY!', 'fairy tales')); - - -// function charMap(str){ -// const charmap = {} -// str = str.toLowerCase().replace(/[\W]/g,'') -// for(let char of str){ -// charmap[char] = ++charmap[char] || 1 -// } -// return charmap -// } - -// function anagrams(stringA, stringB) { -// //Step 1: Build Char Map for stringA -// const charmapA = charMap(stringA) - -// //Step 2: Build Char Map for stringB -// const charmapB = charMap(stringB) - -// //Step 3: Compare each character in the both the Char Maps -// if(Object.keys(charmapA).length !== Object.keys(charmapB).length) return false - -// for(let key in charmapA){ -// if(charmapA[key]!== charmapB[key]) return false -// } - -// return true - -// } \ No newline at end of file diff --git a/completed_exercises/7-vowels.js b/completed_exercises/7-vowels.js deleted file mode 100644 index 5d08808..0000000 --- a/completed_exercises/7-vowels.js +++ /dev/null @@ -1,28 +0,0 @@ -// --- Directions -// Write a function that returns the number of vowels -// used in a string. Vowels are the characters 'a', 'e' -// 'i', 'o', and 'u'. -// --- Examples -// vowels('Hi There!') --> 3 -// vowels('How are you?') --> 5 -// vowels('Coding Money') --> 4 -// vowels('why?') --> 0 - -function vowels(str) { - const vowelCheck = ['a', 'e','i', 'o', 'u'] - - let count = 0 - - for(let char of str.toLowerCase()){ - if(vowelCheck.includes(char)) count++ - } - - return count -} - -console.log(vowels('Coding Money')); - -// function vowels(str) { -// const matches = str.match(/[aeiou]/gi) -// return matches ? matches.length : 0 -// } \ No newline at end of file diff --git a/completed_exercises/8-steps-string-pattern.js b/completed_exercises/8-steps-string-pattern.js deleted file mode 100644 index cd2d4b4..0000000 --- a/completed_exercises/8-steps-string-pattern.js +++ /dev/null @@ -1,34 +0,0 @@ -// --- Directions -// Write a function that accepts a positive number N. -// The function should console log a step shape -// with N levels using the # character. Make sure the -// step has spaces on the right hand side! -// --- Examples -// steps(2) -// '# ' -// '##' -// steps(3) -// '# ' -// '## ' -// '###' -// steps(4) -// '# ' -// '## ' -// '### ' -// '####' - -function steps(n) { - for(let row=1; row<=n; row++){ - let line = '' - for(let col=1; col<=n; col++){ - if(col<=row){ - line += '#' - }else{ - line += ' ' - } - } - console.log(line) - } -} - -steps(6) \ No newline at end of file diff --git a/completed_exercises/9-pyramid.js b/completed_exercises/9-pyramid.js deleted file mode 100644 index be0b353..0000000 --- a/completed_exercises/9-pyramid.js +++ /dev/null @@ -1,32 +0,0 @@ -// --- Directions -// Write a function that accepts a positive number N. -// The function should console log a pyramid shape -// with N levels using the # character. Make sure the -// pyramid has spaces on both the left *and* right hand sides -// --- Examples -// pyramid(1) -// '#' -// pyramid(2) -// ' # ' -// '###' -// pyramid(3) -// ' # ' -// ' ### ' -// '#####' - -function pyramid(n) { - const mid = Math.floor((2*n-1)/2) - for(let row=0; row= mid - row && col<= mid + row ){ - line += '#' - }else{ - line += ' ' - } - } - console.log(line) - } -} - -pyramid(9) \ No newline at end of file