├── .DS_Store ├── 10-fizzbuzz.js ├── README.md ├── completed_exercises ├── 1-reverse-int.js ├── 1-reverse-string.js ├── 10-fizzbuzz.js ├── 11-the-matrix.js ├── 2-palindrome.js ├── 3-maxchars.js ├── 4-array-chunking.js ├── 5-titlecase.js ├── 6-anagrams.js ├── 7-vowels.js ├── 8-steps-string-pattern.js └── 9-pyramid.js └── exercises ├── 1-reverse-int.js ├── 1-reverse-string.js ├── 11-the-matrix.js ├── 2-palindrome.js ├── 3-maxchars.js ├── 4-array-chunking.js ├── 5-titlecase.js ├── 6-anagrams.js ├── 7-vowels.js ├── 8-steps-string-pattern.js └── 9-pyramid.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingmoney/javascript-coding-interview-questions/1b6a3cb43a485ab7bfd98419cb9a3f9859e84d71/.DS_Store -------------------------------------------------------------------------------- /10-fizzbuzz.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a program that console logs the numbers 3 | // from 1 to n. But for multiples of three print 4 | // “fizz” instead of the number and for the multiples 5 | // of five print “buzz”. For numbers which are multiples 6 | // of both three and five print “fizzbuzz”. 7 | // --- Example 8 | // fizzBuzz(5); 9 | // 1 10 | // 2 11 | // fizz 12 | // 4 13 | // buzz 14 | 15 | function fizzBuzz(n) {} 16 | 17 | fizzBuzz(5) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # js-coding-interview-questions 2 | 3 | This repo has been created in support for the Coding Money tutorial videos on youtube. If you want to follow along check out the youtube channel at: http://youtube.com/CodingMoney 4 | -------------------------------------------------------------------------------- /completed_exercises/1-reverse-int.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given an integer, return an integer that is the reverse 3 | // ordering of numbers. 4 | // --- Examples 5 | // reverseInt(15) === 51 6 | // reverseInt(981) === 189 7 | // reverseInt(500) === 5 8 | // reverseInt(-15) === -51 9 | // reverseInt(-90) === -9 10 | 11 | function reverseInt(n) { 12 | const reversed = n.toString().split('').reverse().join('') 13 | return parseInt(reversed) * Math.sign(n) 14 | } 15 | 16 | console.log(reverseInt(-15)); -------------------------------------------------------------------------------- /completed_exercises/1-reverse-string.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return a new string with the reversed order of characters 3 | // --- Examples 4 | // reverse('hi') === 'ih' 5 | // reverse('hello') === 'olleh' 6 | // reverse('CodingMoney') === 'yenoMgnidoC' 7 | 8 | function reverse(str) { 9 | 10 | return str.split('').reverse().join('') 11 | 12 | } 13 | 14 | console.log(reverse('CodingMoney')); 15 | 16 | 17 | // function reverse(str) { 18 | // let reversed = '' 19 | 20 | // for(let char of str){ 21 | // reversed = char + reversed 22 | // } 23 | 24 | // return reversed 25 | // } -------------------------------------------------------------------------------- /completed_exercises/10-fizzbuzz.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a program that console logs the numbers 3 | // from 1 to n. But for multiples of three print 4 | // “fizz” instead of the number and for the multiples 5 | // of five print “buzz”. For numbers which are multiples 6 | // of both three and five print “fizzbuzz”. 7 | // --- Example 8 | // fizzBuzz(5); 9 | // 1 10 | // 2 11 | // fizz 12 | // 4 13 | // buzz 14 | 15 | function fizzBuzz(n) { 16 | for(let i=1; i<=n; i++){ 17 | if(i % 3 === 0 && i % 5 === 0){ 18 | console.log('fizzbuzz') 19 | }else if( i % 3 === 0 ){ 20 | console.log('fizz') 21 | }else if( i % 5 === 0){ 22 | console.log('buzz') 23 | }else{ 24 | console.log(i) 25 | } 26 | } 27 | } 28 | 29 | fizzBuzz(20) -------------------------------------------------------------------------------- /completed_exercises/11-the-matrix.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts an integer N 3 | // and returns a NxN spiral matrix. 4 | // --- Examples 5 | // matrix(2) 6 | // [[1, 2], 7 | // [4, 3]] 8 | // matrix(3) 9 | // [[1, 2, 3], 10 | // [8, 9, 4], 11 | // [7, 6, 5]] 12 | // matrix(4) 13 | // [[1, 2, 3, 4], 14 | // [12, 13, 14, 5], 15 | // [11, 16, 15, 6], 16 | // [10, 9, 8, 7]] 17 | 18 | function matrix(n) { 19 | const result = [] 20 | let counter=1, startRow=0, endRow=n-1, startCol=0, endCol=n-1 21 | for(let i=0; i=startCol; i--){ 42 | result[endRow][i] = counter 43 | counter++ 44 | } 45 | endRow-- 46 | //Left 47 | for(let i=endRow; i>=startRow; i--){ 48 | result[i][startCol] = counter 49 | counter++ 50 | } 51 | startCol++ 52 | } 53 | 54 | return result 55 | } 56 | 57 | console.log(matrix(6)); 58 | -------------------------------------------------------------------------------- /completed_exercises/2-palindrome.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return true if the string is a palindrome 3 | // or false if it is not. Palindromes are strings that 4 | // form the same word if it is reversed. 5 | 6 | // --- Examples: 7 | // palindrome("kayak") === true 8 | // palindrome("madam") === true 9 | // palindrome("codingmoney") === false //yenomgnidoc 10 | 11 | function palindrome(str) { 12 | const reversed = str.split('').reverse().join('') 13 | 14 | return str === reversed 15 | 16 | } 17 | 18 | console.log(palindrome('codingmoney')); -------------------------------------------------------------------------------- /completed_exercises/3-maxchars.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return the character that is most 3 | // commonly used in the string. 4 | // --- Examples 5 | // maxChar("abcccccccd") === "c" 6 | // maxChar("apple 1231111") === "1" 7 | 8 | function maxChar(str) { 9 | const charMap = {} 10 | let max = 0 11 | let maxChar = '' 12 | for(let char of str){ 13 | charMap[char] = ++charMap[char] || 1 14 | } 15 | 16 | for(let key in charMap){ 17 | if(charMap[key] > max){ 18 | max = charMap[key] 19 | maxChar = key 20 | } 21 | } 22 | 23 | return maxChar 24 | } 25 | 26 | console.log(maxChar("apple 1231111")); 27 | 28 | -------------------------------------------------------------------------------- /completed_exercises/4-array-chunking.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given an array and chunk size, divide the array into many subarrays 3 | // where each subarray is of length size 4 | // --- Examples 5 | // chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]] 6 | // chunk([1, 2, 3, 4, 5], 2) --> [[ 1, 2], [3, 4], [5]] 7 | // chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) --> [[ 1, 2, 3], [4, 5, 6], [7, 8]] 8 | // chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]] 9 | // chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]] 10 | 11 | function chunk(array, size) { 12 | const result = [] 13 | let index = 0 14 | while(index 'This Is Mukhtar From Coding Money' 7 | // capitalize('what is titlecase?') --> 'What Is Titlecase?' 8 | // capitalize('titles of books, movies, songs, plays and other works') --> 'Titles Of Books, Movies, Songs, Plays And Other Works' 9 | 10 | function capitalize(str) { 11 | const words = str.split(' ') 12 | //['this', 'is', 'mukhtar'..] 13 | 14 | 15 | return words.map(word => word[0].toUpperCase() + word.slice(1)).join(' ') 16 | 17 | } 18 | 19 | 20 | console.log(capitalize('this is mukhtar from coding money')); -------------------------------------------------------------------------------- /completed_exercises/6-anagrams.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Check to see if two provided strings are anagrams of eachother. 3 | // One string is an anagram of another if it uses the same characters 4 | // in the same quantity. Only consider characters, not spaces 5 | // or punctuation. Consider capital letters to be the same as lower case 6 | // --- Examples 7 | // anagrams('coding money', 'money coding') --> True 8 | // anagrams('RAIL! SAFETY!', 'fairy tales') --> True 9 | // anagrams('Hi there', 'Bye there') --> False 10 | 11 | function cleanStr(str){ 12 | return str.toLowerCase().replace(/[\W]/g,'').split('').sort().join('') 13 | } 14 | function anagrams(stringA, stringB) { 15 | 16 | return cleanStr(stringA) === cleanStr(stringB) 17 | 18 | } 19 | 20 | 21 | console.log(anagrams('RAIL! SAFETY!', 'fairy tales')); 22 | 23 | 24 | // function charMap(str){ 25 | // const charmap = {} 26 | // str = str.toLowerCase().replace(/[\W]/g,'') 27 | // for(let char of str){ 28 | // charmap[char] = ++charmap[char] || 1 29 | // } 30 | // return charmap 31 | // } 32 | 33 | // function anagrams(stringA, stringB) { 34 | // //Step 1: Build Char Map for stringA 35 | // const charmapA = charMap(stringA) 36 | 37 | // //Step 2: Build Char Map for stringB 38 | // const charmapB = charMap(stringB) 39 | 40 | // //Step 3: Compare each character in the both the Char Maps 41 | // if(Object.keys(charmapA).length !== Object.keys(charmapB).length) return false 42 | 43 | // for(let key in charmapA){ 44 | // if(charmapA[key]!== charmapB[key]) return false 45 | // } 46 | 47 | // return true 48 | 49 | // } -------------------------------------------------------------------------------- /completed_exercises/7-vowels.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that returns the number of vowels 3 | // used in a string. Vowels are the characters 'a', 'e' 4 | // 'i', 'o', and 'u'. 5 | // --- Examples 6 | // vowels('Hi There!') --> 3 7 | // vowels('How are you?') --> 5 8 | // vowels('Coding Money') --> 4 9 | // vowels('why?') --> 0 10 | 11 | function vowels(str) { 12 | const vowelCheck = ['a', 'e','i', 'o', 'u'] 13 | 14 | let count = 0 15 | 16 | for(let char of str.toLowerCase()){ 17 | if(vowelCheck.includes(char)) count++ 18 | } 19 | 20 | return count 21 | } 22 | 23 | console.log(vowels('Coding Money')); 24 | 25 | // function vowels(str) { 26 | // const matches = str.match(/[aeiou]/gi) 27 | // return matches ? matches.length : 0 28 | // } -------------------------------------------------------------------------------- /completed_exercises/8-steps-string-pattern.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts a positive number N. 3 | // The function should console log a step shape 4 | // with N levels using the # character. Make sure the 5 | // step has spaces on the right hand side! 6 | // --- Examples 7 | // steps(2) 8 | // '# ' 9 | // '##' 10 | // steps(3) 11 | // '# ' 12 | // '## ' 13 | // '###' 14 | // steps(4) 15 | // '# ' 16 | // '## ' 17 | // '### ' 18 | // '####' 19 | 20 | function steps(n) { 21 | for(let row=1; row<=n; row++){ 22 | let line = '' 23 | for(let col=1; col<=n; col++){ 24 | if(col<=row){ 25 | line += '#' 26 | }else{ 27 | line += ' ' 28 | } 29 | } 30 | console.log(line) 31 | } 32 | } 33 | 34 | steps(6) -------------------------------------------------------------------------------- /completed_exercises/9-pyramid.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts a positive number N. 3 | // The function should console log a pyramid shape 4 | // with N levels using the # character. Make sure the 5 | // pyramid has spaces on both the left *and* right hand sides 6 | // --- Examples 7 | // pyramid(1) 8 | // '#' 9 | // pyramid(2) 10 | // ' # ' 11 | // '###' 12 | // pyramid(3) 13 | // ' # ' 14 | // ' ### ' 15 | // '#####' 16 | 17 | function pyramid(n) { 18 | const mid = Math.floor((2*n-1)/2) 19 | for(let row=0; row= mid - row && col<= mid + row ){ 23 | line += '#' 24 | }else{ 25 | line += ' ' 26 | } 27 | } 28 | console.log(line) 29 | } 30 | } 31 | 32 | pyramid(9) -------------------------------------------------------------------------------- /exercises/1-reverse-int.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given an integer, return an integer that is the reverse 3 | // ordering of numbers. 4 | // --- Examples 5 | // reverseInt(15) === 51 6 | // reverseInt(981) === 189 7 | // reverseInt(500) === 5 8 | // reverseInt(-15) === -51 9 | // reverseInt(-90) === -9 10 | 11 | function reverseInt(n) {} -------------------------------------------------------------------------------- /exercises/1-reverse-string.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return a new string with the reversed order of characters 3 | // --- Examples 4 | // reverse('hi') === 'ih' 5 | // reverse('hello') === 'olleh' 6 | // reverse('CodingMoney') === 'yenoMgnidoC' 7 | 8 | function reverse(str) {} -------------------------------------------------------------------------------- /exercises/11-the-matrix.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts an integer N 3 | // and returns a NxN spiral matrix. 4 | // --- Examples 5 | // matrix(2) 6 | // [[1, 2], 7 | // [4, 3]] 8 | // matrix(3) 9 | // [[1, 2, 3], 10 | // [8, 9, 4], 11 | // [7, 6, 5]] 12 | // matrix(4) 13 | // [[1, 2, 3, 4], 14 | // [12, 13, 14, 5], 15 | // [11, 16, 15, 6], 16 | // [10, 9, 8, 7]] 17 | 18 | function matrix(n) {} 19 | 20 | console.log(matrix(4)); 21 | -------------------------------------------------------------------------------- /exercises/2-palindrome.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return true if the string is a palindrome 3 | // or false if it is not. Palindromes are strings that 4 | // form the same word if it is reversed. 5 | 6 | // --- Examples: 7 | // palindrome("kayak") === true 8 | // palindrome("madam") === true 9 | // palindrome("codingmoney") === false 10 | 11 | function palindrome(str) {} 12 | 13 | -------------------------------------------------------------------------------- /exercises/3-maxchars.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given a string, return the character that is most 3 | // commonly used in the string. 4 | // --- Examples 5 | // maxChar("abcccccccd") === "c" 6 | // maxChar("apple 1231111") === "1" 7 | 8 | function maxChar(str) {} -------------------------------------------------------------------------------- /exercises/4-array-chunking.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Given an array and chunk size, divide the array into many subarrays 3 | // where each subarray is of length size 4 | // --- Examples 5 | // chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]] 6 | // chunk([1, 2, 3, 4, 5], 2) --> [[ 1, 2], [3, 4], [5]] 7 | // chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) --> [[ 1, 2, 3], [4, 5, 6], [7, 8]] 8 | // chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]] 9 | // chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]] 10 | 11 | function chunk(array, size) {} -------------------------------------------------------------------------------- /exercises/5-titlecase.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts a string. The function should 3 | // capitalize the first letter of each word in the string then 4 | // return the capitalized string. 5 | // --- Examples 6 | // capitalize('this is mukhtar from coding money') --> 'This Is Mukhtar From Coding Money' 7 | // capitalize('what is titlecase?') --> 'What Is Titlecase?' 8 | // capitalize('titles of books, movies, songs, plays and other works') --> 'Titles Of Books, Movies, Songs, Plays And Other Works' 9 | 10 | function capitalize(str) {} 11 | 12 | console.log(capitalize('this is mukhtar from coding money')); -------------------------------------------------------------------------------- /exercises/6-anagrams.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Check to see if two provided strings are anagrams of eachother. 3 | // One string is an anagram of another if it uses the same characters 4 | // in the same quantity. Only consider characters, not spaces 5 | // or punctuation. Consider capital letters to be the same as lower case 6 | // --- Examples 7 | // anagrams('coding money', 'money coding') --> True 8 | // anagrams('RAIL! SAFETY!', 'fairy tales') --> True 9 | // anagrams('Hi there', 'Bye there') --> False 10 | 11 | function anagrams(stringA, stringB) {} 12 | 13 | 14 | console.log(anagrams('RAIL! SAFETY!', 'fairy tales')); -------------------------------------------------------------------------------- /exercises/7-vowels.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that returns the number of vowels 3 | // used in a string. Vowels are the characters 'a', 'e' 4 | // 'i', 'o', and 'u'. 5 | // --- Examples 6 | // vowels('Hi There!') --> 3 7 | // vowels('How are you?') --> 5 8 | // vowels('Coding Money') --> 4 9 | // vowels('why?') --> 0 10 | 11 | function vowels(str) {} 12 | 13 | console.log(vowels('Coding Money')); 14 | -------------------------------------------------------------------------------- /exercises/8-steps-string-pattern.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts a positive number N. 3 | // The function should console log a step shape 4 | // with N levels using the # character. Make sure the 5 | // step has spaces on the right hand side! 6 | // --- Examples 7 | // steps(2) 8 | // '# ' 9 | // '##' 10 | // steps(3) 11 | // '# ' 12 | // '## ' 13 | // '###' 14 | // steps(4) 15 | // '# ' 16 | // '## ' 17 | // '### ' 18 | // '####' 19 | 20 | function steps(n) {} 21 | 22 | steps(3) -------------------------------------------------------------------------------- /exercises/9-pyramid.js: -------------------------------------------------------------------------------- 1 | // --- Directions 2 | // Write a function that accepts a positive number N. 3 | // The function should console log a pyramid shape 4 | // with N levels using the # character. Make sure the 5 | // pyramid has spaces on both the left *and* right hand sides 6 | // --- Examples 7 | // pyramid(1) 8 | // '#' 9 | // pyramid(2) 10 | // ' # ' 11 | // '###' 12 | // pyramid(3) 13 | // ' # ' 14 | // ' ### ' 15 | // '#####' 16 | 17 | function pyramid(n) {} 18 | 19 | pyramid(3) --------------------------------------------------------------------------------