Ad
Code
Diff
  • def fizzBuzz(num):
        return 'Fizz' *(not num % 3) + 'Buzz' *(not num % 5) or str(num)
    • def fizzBuzz(num):
    • if num % 3 == 0 and num % 5 != 0:
    • return "Fizz"
    • if num % 3 != 0 and num % 5 == 0:
    • return "Buzz"
    • if num % 3 == 0 and num % 5 == 0:
    • return "FizzBuzz"
    • return str(num)
    • return 'Fizz' *(not num % 3) + 'Buzz' *(not num % 5) or str(num)

Add JS version, more or less like the Python version but more verbose (cuz JS)

Code
Diff
  • const palindrome = (s = '') => s.toLowerCase().split('').reverse().join('') === s.toLowerCase()
    
    • Palindrome = lambda x: x.lower() == x.lower()[::-1]
    • const palindrome = (s = '') => s.toLowerCase().split('').reverse().join('') === s.toLowerCase()

Through the power of javascript being strange, this actually works.

Code
Diff
  • export const fizzBuzz = (i: number): string => ({
      truefalse : 'Fizz',
      falsetrue : 'Buzz',
      truetrue  : 'FizzBuzz',
    }[(i % 3 == 0) + '' + (i % 5 == 0)] || i)
    • export function fizzBuzz(input: number): string {
    • const output = (input % 3 ? "" : "Fizz") + (input % 5 ? "" : "Buzz");
    • return output.length ? output : input.toString();
    • }
    • export const fizzBuzz = (i: number): string => ({
    • truefalse : 'Fizz',
    • falsetrue : 'Buzz',
    • truetrue : 'FizzBuzz',
    • }[(i % 3 == 0) + '' + (i % 5 == 0)] || i)

A simple quicksort solution. Not the prettiest code, but it seems to be correct.

Code
Diff
  • function sortWithoutSort (arr = []) {
      if (arr.length === 0) return []
      let left = [], right = [], pivot = arr[0]
      
      for (let i = 1; i < arr.length; i++) {
        if (arr[i] < pivot) {
          left.push(arr[i])
        } else {
          right.push(arr[i])
        }
      }
      
      return sortWithoutSort(left).concat(pivot, sortWithoutSort(right))
    }
    
    
    • function sortWithoutSort(array) {
    • for (let i = 0; i < array.length; i++) {
    • if (i < array.length - 1) {
    • if (array[i] > array[i+1]) {
    • var sortVal = array.splice(i,1)[0];
    • array.splice(i+1, 0, sortVal);
    • sortWithoutSort(array);
    • }
    • }
    • }
    • function sortWithoutSort (arr = []) {
    • if (arr.length === 0) return []
    • let left = [], right = [], pivot = arr[0]
    • return array;
    • }
    • for (let i = 1; i < arr.length; i++) {
    • if (arr[i] < pivot) {
    • left.push(arr[i])
    • } else {
    • right.push(arr[i])
    • }
    • }
    • return sortWithoutSort(left).concat(pivot, sortWithoutSort(right))
    • }