Ad

Make function negative-safe

Code
Diff
  • def fibonacci(x):
        if x < 0:
            return None
    
        if x == 0 or x == 1:
            return x
    
        return fibonacci(x - 1) + fibonacci(x - 2)
    
    • def fibonacci(x):
    • if x < 0:
    • return None
    • if x == 0 or x == 1:
    • return x
    • else :
    • return fibonacci(x-1) + fibonacci(x-2)
    • return fibonacci(x - 1) + fibonacci(x - 2)

Now with 100% more lambda!

Code
Diff
  • fibonacci = lambda n: n if n == 0 or n == 1 else None if n < 0 else fibonacci(n - 1) + fibonacci(n - 2)
    • def fibonacci(x):
    • if x == 0 or x == 1:
    • return x
    • else :
    • return fibonacci(x-1) + fibonacci(x-2)
    • fibonacci = lambda n: n if n == 0 or n == 1 else None if n < 0 else fibonacci(n - 1) + fibonacci(n - 2)
  • Adds a second argument to generateComment, seed, which allows for deterministic strings
  • Adds a few tests (still bad coverage)
Code
Diff
  • const generateComment = (array = [], seed) =>
      (seed => array.map((each, ii) => each[seed[ii]]).join` `)
        (seed
          ? seed.split`.`.map(Number)
          : array.map(ii => Math.round(Math.random() * (ii.length - 1))))
            
    const dictionary = [
      ['hi,', 'hello,', 'hey,'],
      ['how are'],
      ['you', 'ya'],
      ['doing', 'going'],
      ['?', '?!', '']
    ]
    
    console.log(generateComment(dictionary))
    console.log(generateComment(dictionary, '2.0.1.0.1'))
    • const generateComment = array => array.map(x=>x[Math.floor(Math.random() * x.length)]).join` `
    • const generateComment = (array = [], seed) =>
    • (seed => array.map((each, ii) => each[seed[ii]]).join` `)
    • (seed
    • ? seed.split`.`.map(Number)
    • : array.map(ii => Math.round(Math.random() * (ii.length - 1))))
    • const dictionary = [
    • ['hi,', 'hello,', 'hey,'],
    • ['how are'],
    • ['you', 'ya'],
    • ['doing', 'going'],
    • ['?', '?!', '']
    • ]
    • // console.log(generateComment([['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?', '?!', '']]));
    • console.log(generateComment(dictionary))
    • console.log(generateComment(dictionary, '2.0.1.0.1'))