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
// 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 %> | |
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
//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(''); |
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
/* | |
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? | |
*/ |
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
//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**: |
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 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++) { |
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 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 |
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
let messageBus = { | |
subscribers: [], | |
publish: (message) => { | |
this.subscribers.forEach((subscriber) => { | |
subscriber.fn(message); | |
}); | |
}, | |
subscribe: (type, subscriber, fn) => { | |
this.subscribers.push({ | |
'type': type, |
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 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; |
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
function productExceptSelf(arr){ | |
var temp = []; | |
var product = 1; | |
for(var i = 0; i < arr.length; i++){ | |
temp[i] = product; | |
product *= 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 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) { |
NewerOlder