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)
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()
describe('palindrome', () => { Test.assertEquals(palindrome('mom'), true) Test.assertEquals(palindrome('kAyaK'), true) Test.assertEquals(palindrome('123454321'), true) Test.assertEquals(palindrome('n1oo1n'), true) Test.assertEquals(palindrome('X'), true) Test.assertEquals(palindrome('racecar'), true) Test.assertEquals(palindrome(''), true) Test.assertEquals(palindrome('tacocat'), true) Test.assertEquals(palindrome('rotlor'), false) Test.assertEquals(palindrome('506050'), false) Test.assertEquals(palindrome('idEddEddi'), false) })
Test.describe("Basic Tests")test.assert_equals(Palindrome("MOM"), True)test.assert_equals(Palindrome("kAyaK"), True)test.assert_equals(Palindrome("123454321"), True)test.assert_equals(Palindrome("n1oo1n"), True)test.assert_equals(Palindrome("X"), True)test.assert_equals(Palindrome(""), True)test.assert_equals(Palindrome("n1oo1n"), True)test.assert_equals(Palindrome("rotlor"), False)test.assert_equals(Palindrome("506050"), False)test.assert_equals(Palindrome("idEddEddi"), False)- describe('palindrome', () => {
- Test.assertEquals(palindrome('mom'), true)
- Test.assertEquals(palindrome('kAyaK'), true)
- Test.assertEquals(palindrome('123454321'), true)
- Test.assertEquals(palindrome('n1oo1n'), true)
- Test.assertEquals(palindrome('X'), true)
- Test.assertEquals(palindrome('racecar'), true)
- Test.assertEquals(palindrome(''), true)
- Test.assertEquals(palindrome('tacocat'), true)
- Test.assertEquals(palindrome('rotlor'), false)
- Test.assertEquals(palindrome('506050'), false)
- Test.assertEquals(palindrome('idEddEddi'), false)
- })
Through the power of javascript being strange, this actually works.
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.
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))
- }