Skip to content

Instantly share code, notes, and snippets.

View betterkenly's full-sized avatar

Kenly Hui betterkenly

  • San Francisco
View GitHub Profile
// for desktop (notes: @ab_test_class is a variable to determine the style and this is how i do it in front-end, and the values are // v1,v2,v3,v4 and you can refer the styles below)
<% if @ab_aff_calc %>
<% unless is_mobile? %>
<div id="vu-get-preapproved" class="col-xxs-12 <%= @ab_test_class %>-vu-get-preapproved">
<div class="<%= @ab_test_class %>-vu-get-preapproved-text">Veterans: Get Preapproved for a $0 down VA Loan</div>
</div>
<% end %>
<% end %>
//1
let num = 0;
let reverse = (num) => {
if (num < 0) {
let num1 = num.toString().split('').slice(1).reverse().join('');
return Number(num1) * -1;
} else {
let num1 = num.toString().split('').reverse().join('');
/*
A Thief has a knapsack that can hold X lbs of stolen goods
Each stolen good is worth a certain amount of cash, but
the stolen good also weighs a certain weight. This means that
the thief has to pick an optimal combination of items!
The Thief can't pick the same item twice.
What is the maximum worth of goods that the thief can steal?
*/
@betterkenly
betterkenly / knapsack.js
Created August 9, 2017 23:32 — forked from danwoods/knapsack.js
Knapsack algorithm in JavaScript
//Knapsack algorithm
//==================
// wikipedia: [Knapsack (0/1)](http://en.wikipedia.org/wiki/Knapsack_problem#0.2F1_Knapsack_Problem)
// Given a set `[{weight:Number, benefit:Number}]` and a capacity,
// find the maximum value possible while keeping the weight below
// or equal to the capacity
// **params**:
// `capacity` : Number,
// `items` : [{w:Number, b:Number}]
// **returns**:
var maxEnvelopes = function(envelopes) {
var result = [];
var sorted0 = envelopes.sort((a,b) => {
return a[0] - b[0];
});
var sorted1 = envelopes.sort((a,b) => {
return a[1] - b[1];
});
for (var i = 0; i < sorted0.length; i++) {
var isSubsequence = function(s, t) {
s = s.split('');
t = t.split('');
var curr = 0;
var temp = 0;
for (var i = 0; i < s.length; i++) {
var temp2 = temp;
for (var j = temp2; j < t.length; j++) {
if (t[j] === s[i]) {
temp = j
let messageBus = {
subscribers: [],
publish: (message) => {
this.subscribers.forEach((subscriber) => {
subscriber.fn(message);
});
},
subscribe: (type, subscriber, fn) => {
this.subscribers.push({
'type': type,
var arr = 'what on earth are you talking about'.split('');
// var vowelDoubler = (str) => {
// return str.replace(/[a||e||i||o||u]/gi, myFunc).split('');
// };
var vowelTest = (str) => {
if (str.match(/[a||e||i||o||u]/gi)) {
return true;
function productExceptSelf(arr){
var temp = [];
var product = 1;
for(var i = 0; i < arr.length; i++){
temp[i] = product;
product *= arr[i];
}
var kthSmallest = function(root, k) {
var result = [];
var search = (node) => {
if (node.val !== null) {
result.push(node.val);
}
if (node.left) {
search(node.left);
}
if (node.right) {