[
  {
    "path": ".gitignore",
    "content": "node_modules"
  },
  {
    "path": "Beginner/README.md",
    "content": "# This contains all beginner algorithms and data structures"
  },
  {
    "path": "Beginner/capSentence/index-SOLUTION.js",
    "content": "// USING A FOREACH LOOP\nfunction capSentence(text) {\n    let wordsArray = text.toLowerCase().split(' ')\n    let capsArray = []\n\n    wordsArray.forEach(word => {\n        capsArray.push(word[0].toUpperCase() + word.slice(1))\n    });\n\n    return capsArray.join(' ')\n}\n\n\n// USING .MAP() AND .SLICE()\n\nfunction capSentence(text) {\n    let wordsArray = text.toLowerCase().split(' ')\n    let capsArray = wordsArray.map(word=>{\n        return word[0].toUpperCase() + word.slice(1)\n    })\n\n    return capsArray.join(' ')\n}\n\n\n// USING .MAP() AND .REPLACE()\n\n\nfunction capSentence(text) {\n    let wordsArray = text.toLowerCase().split(' ')\n    \n    let capsArray = wordsArray.map( word=>{\n      return  word.replace(word[0], word[0].toUpperCase())\n    })\n  \n    return capsArray.join(' ')\n  }\n  \n"
  },
  {
    "path": "Beginner/capSentence/index-START.js",
    "content": "/* CHALLENGE\nGiven a sentence containing two or more words, \nreturn the equivalent of the sentence when capitalised. E.g\n  capSentence('the tales of scotch!') // would return 'The Tales Of Scotch!' \n*/\n\n\n\n\nfunction capSentence(text) {\n   // Code goes here\n}\n\n\n\nmodule.exports = capSentence"
  },
  {
    "path": "Beginner/capSentence/test.js",
    "content": "const capSentence = require('./index-START')\n\ntest('capSentence is a function', () => {\n  expect(typeof capSentence).toEqual('function')\n})\n\ntest('capitalizes the first letter of each word in a lowercase sentence', () => {\n  expect(capSentence('i must confess, this is so much fun.')).toEqual(\n    'I Must Confess, This Is So Much Fun.'\n  )\n})\n\ntest('capitalizes the first letter of each word in an uppercase sentence', () => {\n  expect(capSentence('THIS ONE IS FOR SCOTCH.')).toEqual(\n    'This One Is For Scotch.'\n  )\n})\n\ntest('capitalizes the first letter of each word in mixed cased sentences', () => {\n  expect(capSentence('i woulD lOVe to spEAk at jsconF.')).toEqual(\n    'I Would Love To Speak At Jsconf.'\n  )\n})"
  },
  {
    "path": "Beginner/chunkArray/index-FINISHED.js",
    "content": "// LOOPING THROUGH THE ARRAY\n\nfunction chunkArray(array, size) {\n    let result = []\n\n    for (value of array){\n\n        let lastArray = result[result.length -1 ]\n        if(!lastArray || lastArray.length == size){\n            result.push([value])\n        }else{\n            lastArray.push(value)\n        }\n    }\n\n    return result\n}\n\n// LOOPING THROUGH THE NUMBER OF CHUNKS\n\nfunction chunkArray(array, size) {\n    let result = []\n\n    let arrayCopy = [...array]\n\n    while (arrayCopy.length > 0) {\n        result.push(arrayCopy.splice(0, size))\n    }\n\n    return result\n}\n\n\n// USING .SLICE()\n\nfunction chunkArray(array, size) {\n    let result = []\n\n    for (i = 0; i < array.length; i += size) {\n        let chunk = array.slice(i, i + size)\n        result.push(chunk)\n    }\n\n    return result\n}\n\n//RECURSION\n\nfunction chunkArray(array, size) {\n    if(array.length <= size){\n        return [array]\n    }\n    return [array.slice(0,size), ...chunkArray(array.slice(size), size)]\n }"
  },
  {
    "path": "Beginner/chunkArray/index-START.js",
    "content": "/* \n Given two or more arrays, write a function that combines\n their elements into one array without any repetition. \n E.g  mergeArrays([1,2,3,3,3], [1,4,5,2]) // should return [1,2,3,4,5]\n*/\n\nfunction chunkArray(array, size) {\n    // Code goes here\n}\n\n\nmodule.exports = chunkArray"
  },
  {
    "path": "Beginner/chunkArray/test.js",
    "content": "const chunkArray = require('./index-START');\n\ntest('chunkArray is a function', () => {\n  expect(typeof chunkArray).toEqual('function');\n});\n\ntest('Chunks array of 10 elements in twos', () => {\n  const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n  const chunkedArray = chunkArray(arr, 2);\n\n  expect(chunkedArray).toEqual([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]);\n});\n\ntest('Chunks array of 13 elements in five and some', () => {\n  const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];\n  const chunkedArray = chunkArray(arr, 5);\n\n  expect(chunkedArray).toEqual([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13]]);\n});\n"
  },
  {
    "path": "Beginner/factorial/index-SOLUTION.js",
    "content": "// USING A FOR LOOP\n\nfunction factorial(n) {\n    if (n <= 1) {\n        return 1\n    }\n    for (let i = n - 1; i >= 1; i--) {\n        n *= i;\n    }\n    return n;\n}\n\n// USING A WHILE LOOP\n\nfunction factorial(n) {\n    var result = n\n    if (n <= 1) {\n        return 1\n    }\n    while (n > 1) {\n        n--\n        result *= n\n    }\n    return result\n}\n\n// USING RECURSION\n\nfunction factorial(n) {\n    if (n === 0) {\n        return 1\n    }\n    return n * factorial(n - 1)\n}\n\n// USING MEMOIZATION\n\nfunction factorial(n, memo) {\n    memo = memo || {}\n    if(memo[n]){\n        return memo[n]\n    }  \n    if (n === 0) {\n        return 1\n    }\n    return memo[n] = n * factorial(n - 1, memo)\n}"
  },
  {
    "path": "Beginner/factorial/index-START.js",
    "content": "/*\nWrite a function that returns the factorial of \nthe provided integer(n). E.g\n    factorial(5) // should return 120\n*/\n\n\nfunction factorial(n, memo) {\n    memo = memo || {}\n    if(memo[n]){\n        return memo[n]\n    }  \n    if (n === 0) {\n        return 1\n    }\n    return memo[n] = n * factorial(n - 1, memo)\n}\n\nmodule.exports = factorial"
  },
  {
    "path": "Beginner/factorial/test.js",
    "content": "const factorial = require('./index-START')\n\ntest('factorial is a function', () => {\n  expect(typeof factorial).toEqual('function')\n})\n\ntest('returns the factorial of 20', () => {\n  expect(factorial(10)).toEqual(3628800)\n})\n\ntest('returns the factorial of 20', () => {\n  expect(factorial(20)).toEqual(2432902008176640000)\n})\n"
  },
  {
    "path": "Beginner/falsyBouncer/index-SOLUTION.js",
    "content": "// USING A FOR OF LOOP\n\nfunction falsyBouncer(array) {\n    let result =[]\n    \n    for (value of array){\n        if(value){\n            result.push(value)\n        }\n    }\n    \n    return result\n}\n\n// USING .FILTER()\n\nfunction falsyBouncer(array) {\n    return array.filter((value) =>{\n      return Boolean(value)  \n    })\n}\n\n"
  },
  {
    "path": "Beginner/falsyBouncer/index-START.js",
    "content": "/*\nGiven an array, remove all falsy values from the array\nand return an array of only truthy values.\n\nE.g  falsyBouncer([1, 0, null, '', 5]) // should return [1,5]\n*/\n\n\nfunction falsyBouncer(array) {\n    // Code goes here\n}\n\n\nmodule.exports = falsyBouncer"
  },
  {
    "path": "Beginner/falsyBouncer/test.js",
    "content": "const falsyBouncer = require('./index-START');\n\ntest('falsyBouncer is a function', () => {\n    expect(typeof falsyBouncer).toEqual('function');\n});\n\ntest('Removes all falsy values', () => {\n    expect(falsyBouncer([1, 0, null, '', 5])).toEqual([1, 5]);\n})\n\ntest('Removes all falsy values', () => {\n    expect(falsyBouncer([NaN, 0, null, '', undefined])).toEqual([]);\n})\n\n\n\n\n"
  },
  {
    "path": "Beginner/fibonacci/index-SOLUTION.js",
    "content": "// AN ITERATIVE APPROACH\n\nfunction fibonacci(n) {\n    let previous = 1,\n        current = 1\n\n    if (n <= 1) {\n        return 1\n    } else {\n        let counter = n - 1\n\n        while (counter) {\n            let temp = current\n            current += previous\n            previous = temp\n            counter --\n        }\n    }\n    return current\n}\n\n\n// A RECURSIVE SOLUTION\n\nfunction fibonacci(n) {\n    if (n <= 1) {\n        return 1\n    }\n    return fibonacci(n - 1) + fibonacci(n - 2)\n}\n\n// USING MEMOIZATION\n\nfunction fibonacci(n,memo) {\n    memo = memo || {}\n\n    if (memo[n]) {\n        return memo[n]\n    }\n    if (n <= 1) {\n        return 1\n    }\n\n    return memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo)\n}"
  },
  {
    "path": "Beginner/fibonacci/index-START.js",
    "content": "/*\nWrite a function to return the nth element in Fibonacci sequence,\nwhere the sequence is:\n    [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …]\n*/\n\n\nfunction fibonacci(n) {\n    // Code goes here\n}\n\nmodule.exports = fibonacci"
  },
  {
    "path": "Beginner/fibonacci/test.js",
    "content": "const fibonacci = require('./index-START')\n\ntest('fibonacci is a function', () => {\n  expect(typeof fibonacci).toEqual('function')\n})\n\ntest('returns the 6th fibonacci number', () => {\n    expect(fibonacci(6)).toEqual(13)\n  })\n\ntest('returns the 20th fibonacci number', () => {\n  expect(fibonacci(20)).toEqual(10946)\n})\n"
  },
  {
    "path": "Beginner/fizzBuzz/index-SOLUTION.js",
    "content": "// FOR LOOP SOLUTION\n\nfunction fizzBuzz(n) {\n    for (let i = 1; i <= n; i++) {\n        // Is a multiple of 3 and 5?\n        if (i % 15 === 0) {\n            console.log('fizzbuzz')\n        } else if (i % 3 === 0) {\n            // Is a multiple of 3?\n            console.log('fizz')\n        } else if (i % 5 === 0) {\n            // Is a multiple of 5?\n            console.log('buzz')\n        } else {\n            // Is neither of the above?\n            console.log(i)\n        }\n    }\n}\n\n\n// CLEANER AND SMALLER\n\nfunction fizzBuzz(n) {\n    for (let i = 0; i < n;)\n        console.log((++i % 3 ? '' : 'fizz') + (i % 5 ? '' : 'buzz') || i)\n}\n"
  },
  {
    "path": "Beginner/fizzBuzz/index-START.js",
    "content": "/*\n    Write a program that prints the numbers from 1 to n. But for \n    multiples of three print “Fizz” instead of the number and for \n    the multiples of five print “Buzz”. For numbers which are \n    multiples of both three and five print “FizzBuzz”.\n*/\n\n\n\nfunction fizzBuzz(n) {\n    // Code goes here\n}\n\n\nmodule.exports = fizzBuzz"
  },
  {
    "path": "Beginner/fizzBuzz/test.js",
    "content": "const fizzBuzz = require('./index-START');\n\ntest('fizzBuzz is a function', () => {\n  expect(fizzBuzz).toBeDefined();\n});\n\ntest('Calling fizzbuzz with `10` prints out 10 statements', () => {\n  fizzBuzz(10);\n\n  expect(console.log.mock.calls.length).toEqual(10);\n});\n\ntest('Calling fizzbuzz with 15 prints out the correct values', () => {\n  fizzBuzz(15);\n\n  expect(console.log.mock.calls[0][0]).toEqual(1);\n  expect(console.log.mock.calls[1][0]).toEqual(2);\n  expect(console.log.mock.calls[2][0]).toEqual('fizz');\n  expect(console.log.mock.calls[3][0]).toEqual(4);\n  expect(console.log.mock.calls[4][0]).toEqual('buzz');\n  expect(console.log.mock.calls[5][0]).toEqual('fizz');\n  expect(console.log.mock.calls[6][0]).toEqual(7);\n  expect(console.log.mock.calls[7][0]).toEqual(8);\n  expect(console.log.mock.calls[8][0]).toEqual('fizz');\n  expect(console.log.mock.calls[9][0]).toEqual('buzz');\n  expect(console.log.mock.calls[10][0]).toEqual(11);\n  expect(console.log.mock.calls[11][0]).toEqual('fizz');\n  expect(console.log.mock.calls[12][0]).toEqual(13);\n  expect(console.log.mock.calls[13][0]).toEqual(14);\n  expect(console.log.mock.calls[14][0]).toEqual('fizzbuzz');\n});\n\nbeforeEach(() => {\n  jest.spyOn(console, 'log').mockImplementation(() => {});\n});\n\nafterEach(() => {\n  console.log.mockRestore();\n});\n"
  },
  {
    "path": "Beginner/hammingDistance/index-SOLUTION.js",
    "content": "// USING FOR LOOP\nfunction hammingDistance(stringA, stringB) {\n    let result = 0\n\n    if (stringA.length == stringB.length) {\n\n        for (let i = 0; i < stringA.length; i++) {\n            if (stringA[i].toLowerCase() != stringB[i].toLowerCase()) {\n                result++\n            }\n        }\n        return result\n    } else {\n        throw new Error('Strings do not have equal length')\n    }\n}"
  },
  {
    "path": "Beginner/hammingDistance/index-START.js",
    "content": "/* CHALLENGE\nGiven two strings of equal length, calculate and return the the hamming distance.\nE.g hammingDistance('rover', 'river') // should return 1\n*/\n\n\n\n\nfunction hammingDistance(stringA, stringB) {\n    // Code goes here\n}\n\n\n\nmodule.exports = hammingDistance"
  },
  {
    "path": "Beginner/hammingDistance/test.js",
    "content": "const hammingDistance = require('./index-START')\n\ntest('hammingDistance is a function', () => {\n  expect(typeof hammingDistance).toEqual('function')\n})\n\ntest('returns the hamming distance for letters', () => {\n  expect(hammingDistance('river', 'rover')).toEqual(1)\n})\n\ntest('returns the hamming distance for numbers', () => {\n  expect(hammingDistance('1011101', '1001001')).toEqual(2)\n})\n\ntest('returns the hamming distance for letters', () => {\n  expect(hammingDistance('karolin', 'kerstin')).toEqual(3)\n})\n\ntest('returns the hamming distance for letters', () => {\n  expect(hammingDistance('drummer', 'dresser')).toEqual(3)\n})\n\n\n"
  },
  {
    "path": "Beginner/isAnagram/index-SOLUTION.js",
    "content": "// DIRECT COMPARISON\n\nfunction isAnagram(stringA, stringB) {\n\n    const sanitizeString = function (str) {\n        return str.toLowerCase().replace(/[^a-z\\d]/g, '').split('').sort().join('');\n    }\n\n    return sanitizeString(stringA) == sanitizeString(stringB)\n\n}\n\n// CHARACTER MAP COMPARISON\n\nfunction isAnagram(stringA, stringB) {\n\n    function createCharMap(text) {\n        let charMap = {}\n        for (let char of text) {\n            if (charMap.hasOwnProperty(char)) {\n                charMap[char]++\n            } else {\n                charMap[char] = 1\n            }\n        }\n        return charMap\n    }\n\n    if (stringA.length === stringB.length) {\n\n        let stringAMap = createCharMap(stringA)\n        let stringBMap = createCharMap(stringB)\n\n        for (let char in stringAMap) {\n            if (stringAMap[char] !== stringBMap[char]) {\n                return false\n            }\n        }\n\n        return true\n    } else {\n        return false\n    }\n}"
  },
  {
    "path": "Beginner/isAnagram/index-START.js",
    "content": "/* CHALLENGE\nGiven a two strings, write an algorithm to check if they are anagrams\nof each other. Return true if the pass the test and false if they\ndon't. E.g\n    isAnagram('silent', 'listen') // should return true\n*/\n\n\n\nfunction isAnagram(stringA, stringB) {\n    // Code goes here\n}\n\n\nmodule.exports = isAnagram"
  },
  {
    "path": "Beginner/isAnagram/test.js",
    "content": "const isAnagram = require('./index-START')\n\ntest('isAnagram is a function', () => {\n  expect(typeof isAnagram).toEqual('function')\n})\n\ntest('\"dog\" is an anagram of \"god\"', () => {\n  expect(isAnagram('dog', 'god')).toBeTruthy()\n})\n\ntest('\"Scotchy is Scotch!\" is an anagram of \"Scotch is Scotchy!\"', () => {\n  expect(isAnagram('Scotchy is Scotch!', 'Scotch is Scotchy!')).toBeTruthy()\n})\n\ntest('\"I do not work weekends.\" is not an anagram of \"I do not work weekdays!\"', () => {\n  expect(isAnagram('I do not work weekends.', 'I do not work weekdays!')).toBeFalsy()\n})"
  },
  {
    "path": "Beginner/longestWord/index-SOLUTION.js",
    "content": "// USING A FOR LOOP\n\nfunction longestWord(text) {\n    let wordArray = text.split(' ')\n    let maxLength = 0\n    let result = ''\n    for (let i = 0; i < wordArray.length; i++) {\n        if (wordArray[i].length > maxLength) {\n            maxLength = wordArray[i].length\n            result = wordArray[i]\n        }\n    }\n    return result\n}\n\n\n\n// USING .REDUCE()\n\nfunction longestWord(text) {\n    var result = text.split(' ').reduce((maxLengthWord, currentWord) => {\n        if (currentWord.length > maxLengthWord.length) {\n            return currentWord\n        } else {\n            return maxLengthWord\n        }\n    }, \"\")\n    return result\n}\n\n\n// USING .SORT()\n\nfunction longestWord(text) {\n\n    var sortedArray = text.split(' ')\n                          .sort((wordA, wordB) => wordB.length - wordA.length)\n\n    return sortedArray[0]\n}"
  },
  {
    "path": "Beginner/longestWord/index-START.js",
    "content": "/* CHALLENGE\nGiven a string of text, write an algorithm that returns the text received in a reversed format. \nE.g reverseString('algorithms') // should return 'smhtirogla'\n*/\n\n\n\nfunction longestWord(text) {\n    // Code goes here\n}\n\n\nmodule.exports = longestWord"
  },
  {
    "path": "Beginner/longestWord/test.js",
    "content": "const longestWord = require('./index-START')\n\ntest('longestWord is a function', () => {\n  expect(typeof longestWord).toEqual('function');\n});\n\ntest('returns the longet word in a mixed case string of text', () => {\n  expect(longestWord('Top Shelf Web Development Training on Scotch') ).toEqual('Development');\n});\n\ntest('returns the longet word in a lowercase string', () => {\n  expect(longestWord('the ultimate guide to js algorithms') ).toEqual('algorithms');\n});\ntest('returns the longet word in an uppercase string', () => {\n  expect(longestWord('BUILDING FOR THE NEXT BILLION USERS') ).toEqual('BUILDING');\n});"
  },
  {
    "path": "Beginner/maxRecurringChar/index-SOLUTION.js",
    "content": "// FOR...IN ITERATION METHOD\nfunction maxRecurringChar(text) {\n    let charMap = {}\n    let maxCharValue = 0\n    let maxChar = ''\n    for (let char of text) {\n        if (charMap.hasOwnProperty(char)) {\n            charMap[char]++\n        } else {\n            charMap[char] = 1\n        }\n    }\n    for (let char in charMap) {\n        if (charMap[char] > maxCharValue) {\n            maxCharValue = charMap[char]\n            maxChar = char\n        }\n    }\n    return maxChar\n}\n\n// FORMING ARRAYS FROM THE CHARACTER MAP METHOD\nfunction maxRecurringChar(text) {\n    let charMap = {}\n    let charArray =[]\n    let vaulesArray = []\n    let maxCharValue = 0\n\n    for (let char of text) {\n        if (charMap.hasOwnProperty(char)) {\n            charMap[char]++\n        } else {\n            charMap[char] = 1\n        }\n    }\n    charArray = Object.keys(charMap)\n    vaulesArray = Object.values(charMap)\n    maxCharValue = Math.max(...vaulesArray)\n    \n    return charArray[vaulesArray.indexOf(maxCharValue)]\n}"
  },
  {
    "path": "Beginner/maxRecurringChar/index-START.js",
    "content": "/* CHALLENGE\nGiven a string of text, find and return the most recurring character. \ne.g maxRecurringChar('aabacada') // will return 'a'\n*/\n\n\n\nfunction maxRecurringChar(text) {\n    // Code goes here\n}\n\n\n\nmodule.exports = maxRecurringChar;"
  },
  {
    "path": "Beginner/maxRecurringChar/test.js",
    "content": "const maxRecurringChar = require('./index-START');\n\ntest('maxRecurringChar is a function', () => {\n  expect(typeof maxRecurringChar).toEqual('function');\n});\n\ntest('Finds the most frequently used character', () => {\n  expect(maxRecurringChar('sisusbsnshsjsmskslstsw')).toEqual('s');\n});\n\ntest('Finds the most frequently used character even with mixed capitalization', () => {\n  expect(maxRecurringChar('AbAdAabnmkAAAynjfaA')).toEqual('A');\n});\n\ntest('Finds the most used number as well', () => {\n  expect(maxRecurringChar('b2n3n2m2l2k2i2o2')).toEqual('2');\n});\n"
  },
  {
    "path": "Beginner/mergeArrays/index-FINISHED.js",
    "content": "// USING A SET\nfunction mergeArrays(...arrays) {\n\n    let jointArray = []\n    \n    arrays.forEach(array => {\n        jointArray = [...jointArray, ...array]\n    });\n\n    return [...new Set([...jointArray])]\n\n}\n\n// USING ARRAY.FROM() WITH SET\n\nfunction mergeArrays(...arrays) {\n    let jointArray = []\n    \n    arrays.forEach(array => {\n        jointArray = [...jointArray, ...array]\n    });\n    return Array.from(new Set([...jointArray]))\n}\n\n// USING .FILTER()\n\nfunction mergeArrays(...arrays) {\n\n    let jointArray = []\n    \n    arrays.forEach(array => {\n        jointArray = [...jointArray, ...array]\n    })\n\n    const uniqueArray = jointArray.filter((item,index) => jointArray.indexOf(item) === index)\n\n    return uniqueArray\n}\n\n// USING .REDUCE()\n\nfunction mergeArrays(...arrays) {\n\n    let jointArray = []\n    \n    arrays.forEach(array => {\n        jointArray = [...jointArray, ...array]\n    })\n\n    const uniqueArray = jointArray.reduce((newArray, item) =>{\n        if (newArray.includes(item)){\n            return newArray\n        } else {\n            return [...newArray, item]\n        }\n    }, [])\n\n    return uniqueArray\n}"
  },
  {
    "path": "Beginner/mergeArrays/index-START.js",
    "content": "/*\n Given two or more arrays, write a function that combines\n their elements into one array without any repetition. \n E.g mergeArrays([1,2,3,3,3], [1,4,5,2]) // should return [1,2,3,4,5]\n*/\n\nfunction mergeArrays(...arrays) {\n\n    let jointArray = []\n    \n    arrays.forEach(array => {\n        jointArray = [...jointArray, ...array]\n    });\n\n    return [...new Set([...jointArray])]\n\n    \n}\n\n\nmodule.exports = mergeArrays"
  },
  {
    "path": "Beginner/mergeArrays/test.js",
    "content": "const mergeArrays = require('./index-START');\n\ntest('mergeArrays is a function', () => {\n  expect(typeof mergeArrays).toEqual('function');\n});\n\ntest('Combines 5 arrays of numbers without dubplicates', () => {\n  expect(mergeArrays([1,2],[2,3],[3,4],[4,5])).toEqual([1,2,3,4,5]);\n});\n\ntest('Combines 3 arrays of strings without dubplicates', () => {\n  expect(mergeArrays(['a','b','z'],['m','n','a'],['z','y'])).toEqual(['a','b', 'z', 'm', 'n', 'y']);\n});\n\n\n"
  },
  {
    "path": "Beginner/palindromeChecker/index-SOLUTION.js",
    "content": "// AN INTUITIVE APPROACH\n\nfunction palindromeChecker(text) {\n\n    var reversedText = text.toLowerCase()\n        .split('').reverse().join('')\n\n    return text === reversedText\n}\n\n\n// LOOPING THROUGH AND COMPARING CHARACTERS\n\n\nfunction palindromeChecker(text) {\n    let charArray = text.toLowerCase().split('')\n\n    let result = charArray.every((letter, index) => {\n        return letter === charArray[charArray.length - index - 1];\n    })\n\n    return result\n}\n\n// LOOPING THROUGH AND COMPARING CHARACTERS(OPTIMIZED)\n\n\nfunction palindromeChecker(text) {\n    var textLen = text.length;\n    for (var i = 0; i < textLen / 2; i++) {\n        if (text[i] !== text[textLen - 1 - i]) {\n            return false;\n        }\n    }\n    return true;\n}"
  },
  {
    "path": "Beginner/palindromeChecker/index-START.js",
    "content": "/* CHALLENGE\nGiven a string of text, return true or false indicating whether or not the text is a palindrome.\ne.g palindromeChecker('racecar') // will return true\n*/\n\n\n\n\nfunction palindromeChecker(text) {\n    v// Code goes here\n}\n\n\n\nmodule.exports = palindromeChecker;"
  },
  {
    "path": "Beginner/palindromeChecker/test.js",
    "content": "const palindromeChecker = require('./index-START');\n\ntest('palindromeChecker is a function', () => {\n  expect(typeof palindromeChecker).toEqual('function');\n});\n\ntest('\"php\" is a palindrome', () => {\n  expect(palindromeChecker('php')).toBeTruthy();\n});\n\ntest('\" php  \" is not a palindrome', () => {\n  expect(palindromeChecker(' php  ')).toBeFalsy();\n});\n\ntest('\"developer\" is not a palindrome', () => {\n  expect(palindromeChecker('developer')).toBeFalsy();\n});\n\ntest('\"2002\" a palindrome', () => {\n  expect(palindromeChecker('2002')).toBeTruthy();\n});\n\n"
  },
  {
    "path": "Beginner/reverseString/index-SOLUTION.js",
    "content": "// CHAINING BUILT-IN METHODS\n\nfunction reverseString(text) {\n    return text.split(\"\").reverse().join(\"\");\n}\n\n//  CHAINING BUILT-IN METHODS USING ES6\n\nfunction reverseString(text) {\n    return [...text].reverse().join('');\n}\n\n// USING A FOR LOOP\n\nfunction reverseString(text) {\n    let result = \"\";\n    for (let i = text.length - 1; i >= 0; i--) {\n        result += text[i];\n    }\n    return result;\n}\n\n// USING A FOR..OF LOOP IN ES6\n\nfunction reverseString(text) {\n    let result = \"\";\n    for (let char of text) {\n        result = char + result\n    }\n    return result;\n}\n\n// RECURSIVE METHOD\n\nfunction reverseString(text) {\n    if (text === \"\") {\n        return \"\"\n    } else {\n        return reverseString(text.substr(1)) + text[0]\n    }\n}\n\n\n// USING .REDUCE()\n\nfunction reverseString(text) {\n    return text.split(\"\").reduce((acc, char) => char + acc);\n}"
  },
  {
    "path": "Beginner/reverseString/index-START.js",
    "content": "/* CHALLENGE\nGiven a string of text, write an algorithm that returns the text received in a reversed format. \nE.g reverseString('algorithms') // should return 'smhtirogla'\n*/\n\n\n\nfunction reverseString(text) {\n    // Code goes here\n}\n\n\n\nmodule.exports = reverseString"
  },
  {
    "path": "Beginner/reverseString/test.js",
    "content": "const reverseString = require('./index-START')\n\ntest('reverseString is a function', () => {\n  expect(typeof reverseString).toEqual('function');\n});\n\ntest('reverses a string of text', () => {\n  expect(reverseString('aeiou')).toEqual('uoiea');\n});\n\ntest('reverses a string containing numbers', () => {\n  expect(reverseString('123456789')).toEqual('987654321');\n});\n\ntest('reverses a string containing mixed case characters', () => {\n  expect(reverseString('AsDfGhJkL')).toEqual('LkJhGfDsA');\n});\n\n\n\n"
  },
  {
    "path": "Beginner/searchReplace/index-SOLUTION.js",
    "content": ""
  },
  {
    "path": "Beginner/searchReplace/index-START.js",
    "content": ""
  },
  {
    "path": "Beginner/searchReplace/test.js",
    "content": ""
  },
  {
    "path": "Beginner/vowelsCounter/index-SOLUTION.js",
    "content": "// ITERATIVE APPROACH\nconst vowels = [\"a\", \"e\", \"i\", \"o\", \"u\"]\n\n\nfunction vowelsCounter(text) {\n    // Initialize counter\n    let counter = 0;\n\n\n    // Loop through text to test if each character is a vowel\n    for (let letter of text.toLowerCase()) {\n        if (vowels.includes(letter)) {\n            counter++\n        }\n    }\n\n    // Return number of vowels\n    return counter\n}\n\n// REGULAR EXPRESSIONS\n\nfunction vowelsCounter(text) {\n    // Search text with Regex and store all matching instances \n    let matchingInstances = text.match(/[aeiou]/gi);\n\n    // Check if matching instances exist then calculate length\n    if (matchingInstances) {\n        // Return number of vowels\n        return matchingInstances.length\n    } else {\n        return 0\n    }\n}\n"
  },
  {
    "path": "Beginner/vowelsCounter/index-START.js",
    "content": "/* CHALLENGE\nGiven a string of text, return the number of vowels found within the text\ne.g vowelsCounter('anehizxcv') // will return 3\n*/\n\n\nfunction vowelsCounter(text) {\n    // Code goes here\n}\n\n\n\nmodule.exports = vowelsCounter;\n"
  },
  {
    "path": "Beginner/vowelsCounter/test.js",
    "content": "const vowelsCounter = require('./index-START');\n\ntest('vowelsCounter is a function', () => {\n  expect(typeof vowelsCounter).toEqual('function');\n});\n\ntest('returns the number of vowels found', () => {\n  expect(vowelsCounter('aeiou')).toEqual(5);\n});\n\ntest('returns the number of vowels found when string is capitalized', () => {\n  expect(vowelsCounter('AEIOU')).toEqual(5);\n});\n\ntest('returns the number of vowels found when all alphabets are passed in', () => {\n  expect(vowelsCounter('abcdefghijklmnopqrstuvwxyz')).toEqual(5);\n});\n\ntest('returns the number of vowels found when string has mixed capitalization', () => {\n  expect(vowelsCounter('Abcdegfizzjbhso')).toEqual(4);\n});\n"
  },
  {
    "path": "Beginner/whereIBelong/index-SOLUTION.js",
    "content": "// ITERATING AND COMPARING WITH A FORLOOP(BY FINDING THE IMMEDIATE LARGER VALUE)\n\nfunction whereIBelong(arr, num) {\n    arr.sort((a, b) => {\n        return a - b\n    })\n\n    for (var i = 0; i < arr.length; i++) {\n        if (arr[i] >= num) {\n            return i\n        }\n    }\n\n    return arr.length\n\n}\n\n// ITERATING AND COMPARING WITH A FORLOOP(BY COUNTING ALL SMALLER VALUES)\n\nfunction whereIBelong(arr, num) {\n\n    var counter = 0\n    for (i = 0; i < arr.length; i++) {\n        if (num > arr[i]) {\n            counter++\n        }\n    } \n\n    return counter\n}\n\n\n// USING A WHILE LOOP\n\nfunction whereIBelong(arr, num) {\n    arr.sort((a, b) => {\n        return a - b\n    })\n\n    let counter = 0;\n    while (num > arr[counter]) {\n        counter++\n    }\n\n    return counter\n}\n\n\n// FINDING THE NUMBER'S INDEX IN THE ARRAY\n\nfunction whereIBelong(arr, num) {\n    arr.push(num)\n\n    arr.sort((a, b) => a - b)\n\n    return arr.indexOf(num)\n\n}"
  },
  {
    "path": "Beginner/whereIBelong/index-START.js",
    "content": "/*\nReturn the lowest index at which a value (second argument) should be\ninserted into an array (first argument) once it has been sorted. The\nreturned value should be a number. E.g\n\nwhereIBelong([1,2,3,4], 1.5) // should return 1 because it is greater\nthan 1(index 0), but less than 2(index 1).\n*/\n\n\n\nfunction whereIBelong(arr, num) {\n   // Code goes here\n\n}\n\n\n\nmodule.exports = whereIBelong"
  },
  {
    "path": "Beginner/whereIBelong/test.js",
    "content": "const whereIBelong = require('./index-START');\n\ntest('whereIBelong is a function', () => {\n  expect(typeof whereIBelong).toEqual('function');\n});\n\ntest('returns the appropriate index', () => {\n  expect(whereIBelong([1,2,3,4], 1.5)).toEqual(1);\n});\n\n\ntest('returns the index of the specified number', () => {\n  expect(whereIBelong([10, 20, 30, 40, 50], 30)).toEqual(2);\n});\n\ntest('returns the index even with an empty array', () => {\n  expect(whereIBelong([], 1)).toEqual(0);\n});\n\n"
  },
  {
    "path": "README.md",
    "content": "# js-algorithms-demo-\nDemo repository for JS Algorithms Course\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"js-algorithms\",\n  \"version\": \"1.0.0\",\n  \"description\": \"sample course setup\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"jest\"\n  },\n  \"author\": \"Obosi Philip\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"jest\": \"^23.6.0\"\n  }\n}\n"
  }
]