Skip to content

Instantly share code, notes, and snippets.

View vivatolu's full-sized avatar

Tolu Atanda vivatolu

  • Washington, DC area
View GitHub Profile
@vivatolu
vivatolu / tree.md
Created March 17, 2021 02:33 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@vivatolu
vivatolu / gist:2815d1b9915976cbd8cd
Created November 25, 2015 15:41
http://www.freecodecamp.com/vivatolu 's solution for Bonfire: Check for Palindromes
// Bonfire: Check for Palindromes
// Author: @vivatolu
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20var%20n%20%3D%20str.toLowerCase()%3B%0A%20%20var%20m%20%3D%20n.replace(%2F%5B%5Ea-zA-Z0-9%5D%2B%2Fg%2C%20%27%27)%3B%0A%20%20var%20y%20%3D%200%3B%0A%20%20for(var%20x%20%3D%20(m.length%20-%201)%3B%20x%3Ey%3B%20x--%20%26%26%20y%2B%2B)%7B%0A%20%20%20%20if(m%5Bm.length%2F2%5D%20!%3D%3D%20m%5Bm.length%2F2%20-1%5D)%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7Delse%20if(m%5Bx%5D%20%3D%3D%3D%20m%5By%5D)%7B%0A%09%09return%20true%3B%0A%09%7D%20else%20%7B%0A%09%09return%20false%3B%0A%09%7D%0A%0A%09%0A%7D%0A%7D%0Apalindrome(%22eye%22)%3B%0A%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
var n = str.toLowerCase();
var m = n.replace(/[^a-zA-Z0-9]+/g, '');
var y = 0;
for(var x = (m.length - 1); x>y; x-- && y++){