This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Truncate a string | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string?solution=function%20truncate(str%2C%20num)%20%7B%0A%20%20%2F%2F%20Clear%20out%20that%20junk%20in%20your%20trunk%0A%20%20if(num%3Cstr.length)%20%7B%0A%20%20%20%20return%20num%3E3%20%3F%20str.slice(0%2Cnum-3).concat(%27...%27)%3Astr.slice(0%2Cnum).concat(%27...%27)%3B%0A%20%20%7D%0A%20%20return%20str%3B%0A%7D%0A%0Atruncate(%22A-tisket%20a-tasket%20A%20green%20and%20yellow%20basket%22%2C%2011)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function truncate(str, num) { | |
| // Clear out that junk in your trunk | |
| if(num<str.length) { | |
| return num>3 ? str.slice(0,num-3).concat('...'):str.slice(0,num).concat('...'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Chunky Monkey | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey?solution=function%20chunk(arr%2C%20size)%20%7B%0A%20%20resultArray%20%3D%20%5B%5D%3B%0A%20%20flag%3Dtrue%3B%0A%20%20start%3D0%3B%0A%20%20end%3Dsize%3B%0A%20%20%2F%2F%20Break%20it%20up.%0A%20%20while(flag)%20%7B%0A%20%20%20%20%20a%20%3D%20arr.slice(start%2Cend)%3B%0A%20%20%20%20%20if(a.length)%20%7B%0A%20%20%20%20%20%20%20resultArray.push(a)%3B%0A%20%20%20%20%20%20%20start%3Dend%3B%0A%20%20%20%20%20%20%20end%3Dend%2Bsize%3B%0A%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20flag%3Dfalse%3B%0A%20%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20resultArray%3B%0A%7D%0A%0Achunk(%5B%22a%22%2C%20%22b%22%2C%20%22c%22%2C%20%22d%22%5D%2C%202)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function chunk(arr, size) { | |
| resultArray = []; | |
| flag=true; | |
| start=0; | |
| end=size; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Mutations | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20list%20%3D%20arr%5B1%5D.toLowerCase().split(%22%22)%3B%0A%20%20for(i%3D0%3Bi%3Clist.length%3Bi%2B%2B)%7B%0A%20%20%20%20if(arr%5B0%5D.toLowerCase().indexOf(list%5Bi%5D)%3C0)%20%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20true%3B%0A%7D%0A%0A%0Amutation(%5B%22hello%22%2C%20%22hey%22%5D)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function mutation(arr) { | |
| list = arr[1].toLowerCase().split(""); | |
| for(i=0;i<list.length;i++){ | |
| if(arr[0].toLowerCase().indexOf(list[i])<0) { | |
| return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Falsy Bouncer | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer?solution=function%20bouncer(arr)%20%7B%0A%20%20%2F%2F%20Don%27t%20show%20a%20false%20ID%20to%20this%20bouncer.%0A%20%20return%20arr.filter(function(value)%20%7B%0A%20%20%20%20return%20value%3Ftrue%3Afalse%3B%0A%20%20%7D)%3B%0A%7D%0A%0Abouncer(%5B7%2C%20%22ate%22%2C%20%22%22%2C%20false%2C%209%5D)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function bouncer(arr) { | |
| // Don't show a false ID to this bouncer. | |
| return arr.filter(function(value) { | |
| return value?true:false; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Seek and Destroy | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=function%20destroyer(arr)%20%7B%0A%20%20%20args%20%3D%20Array.prototype.slice.call(arguments)%3B%0A%20%20%20args.slice(1).forEach(function(e%2Cl%2Ca)%20%7B%0A%20%20%20arr%20%3D%20arr.filter(function(value)%20%7B%0A%20%20%20%20%20%20%20console.log(value%3D%3De)%3B%0A%20%20%20%20%20%20%20return%20(value!%3De)%3B%0A%20%20%20%20%20%7D)%3B%0A%20%20%20%7D)%3B%0A%20%20return%20arr%3B%0A%7D%0A%0Adestroyer(%5B%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%2C%202%2C%203%5D)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function destroyer(arr) { | |
| args = Array.prototype.slice.call(arguments); | |
| args.slice(1).forEach(function(e,l,a) { | |
| arr = arr.filter(function(value) { | |
| console.log(value==e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Slasher Flick | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick?solution=function%20slasher(arr%2C%20howMany)%20%7B%0A%20%20%2F%2F%20it%20doesn%27t%20always%20pay%20to%20be%20first%0A%20%20a%20%3D%20arr.splice(0%2ChowMany)%3B%0A%20%20return%20arr%3B%0A%7D%0A%0Aslasher(%5B1%2C%202%2C%203%5D%2C%202)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function slasher(arr, howMany) { | |
| // it doesn't always pay to be first | |
| a = arr.splice(0,howMany); | |
| return arr; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bonfire: Where do I belong | |
| // Author: @srkama | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function where(arr, num) { | |
| // Find my place in this sorted array. | |
| arr.sort(function(a,b){return a-b;}); | |
| for (i=0;i<=arr.length;i++) { | |
| if (num<=arr[i]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var gulp = require('gulp'), | |
| concat = require('gulp-concat'), | |
| livereload = require('gulp-livereload'), | |
| minifyCSS = require('gulp-minify-css'), | |
| uglify = require('gulp-uglify'), | |
| sass = require('gulp-sass'), | |
| watch = require('gulp-watch'), | |
| sequence = require('gulp-watch-sequence'); | |
| var paths = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| def object_to_dict(obj): | |
| """ | |
| Method to get dict of object properties. This method identified object properties and returns | |
| a dict of properties with key, value as property name and property value respectively | |
| :param : object | |
| :return: obj_dict : dict | |
| """ | |
| obj_dict = {} | |
| print vars(obj.__class__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pairs = [["A", "T"],["C","G"]] | |
| function pair(str) { | |
| tempArray = []; | |
| for (j=0;j<str.length;j++){ | |
| for (i=0;i<pairs.length;i++) { | |
| indexValue = pairs[i].indexOf(str.charAt(j)); | |
| if(indexValue==0) { | |
| tempArray.push(pairs[i].slice()); | |
| } else if (indexValue == 1) { | |
| pairs[i].reverse(); |