Skip to content

Instantly share code, notes, and snippets.

function User(){
var self=this;
self.rank = -8;
self.progress = 0;
self.incProgress = function(pRank){
if(pRank>8 || pRank<-8 || pRank===0){
throw new Error("Rank cannot be greater than 8 or less than -8 or equal to 0");
}
if(self.rank>=8){
self.progress=0;

Instructions:

You are writing an app that displays a fixed width font and has a strict limit of 25 characters per line in one particular text area.

Write a function that takes in a string, inserts newline characters, and adds a hyphen on the end of a line if a word is continued on the next line.

White space should not be left in the result string as is.

Test Fixture Cut-n-Paste:

// TODO: create UriBuilder object
UriBuilder = function(url){
var self = this;
var makeParams = function(params){
var pairs = [];
for(var key in params){
if(params.hasOwnProperty(key)){
pairs.push(key+"="+params[key]);
}
@CitizenOfRome
CitizenOfRome / isValidIP.js
Last active December 20, 2015 14:49
http://www.codewars.com/dojo/katas/515decfd9dcfc23bb6000006/play/javascript Write an algorithm that will identify valid IPv4 addresses in dot-decimal format. Input to the isValidIP function is guaranteed to be a single string. Examples of valid inputs: 1.2.3.4 123.45.67.89 Examples of invalid inputs: 1.2.3 1.2.3.4.5 123.456.78.90 123.045.067.089
function isValidIP(str) {
var parts = str.split(".").filter(function(el){
if(!el.length || el.length>3) return false
var item=parseInt(el,10);
return (el.length>1?el.indexOf(0)!==0:true) && item>=0 && item<=255;
});
return parts.length===4;
}
// No idea what's wrong
(function ($) {
"use strict";
function getValue(id) {
return parseInt($("#" + id).text().split(": ")[1], 10);
}
function click(id) {
return $("." + id).trigger('click');
}
import math
t=input()
for x in range(t):print "%.15f"%sum([math.pow(-1,i)/(2*i+1) for i in range(input())])
#!/usr/bin/python
# Head ends here
stack=[]
stapp = stack.append
def dfs( x, y, pacman_x, pacman_y, food_x, food_y, grid):
stapp([pacman_x, pacman_y])
if pacman_x==food_x and pacman_y==food_y: return True
if pacman_x>0 and grid[pacman_x-1][pacman_y]!='%':
dfs(x, y, pacman_x-1, pacman_y, food_x, food_y, grid)
if pacman_y<y-1 and grid[pacman_x][pacman_y+1]!='%':
#!/usr/bin/python
import math
import random
def getArrayIndex(stringIndex, n):
stringIndex += 1 # Switch base to 1 from 0
row = math.ceil(float(stringIndex)/n)
col = stringIndex - (row-1)*n
return row-1, col-1 #Switch back to 0 index
def findall_iter(sub, string):
#!/usr/bin/python
import math
import random
def getArrayIndex(stringIndex, size):
stringIndex += 1 # Switch base to 1 from 0
row = math.ceil(float(stringIndex)/size)
col = stringIndex - (row-1)*size
return row-1, col-1 #Switch back to 0 index
def findall_iter(sub, string):
#!/usr/bin/python
import math
def getArrayIndex(stringIndex, size):
stringIndex += 1 # Switch base to 1 from 0
row = math.ceil(float(stringIndex)/size)
col = stringIndex - (row-1)*size
return row-1, col-1 #Switch back to 0 index
def findall_iter(sub, string):
"""http://stackoverflow.com/a/3874760/937891