Skip to content

Instantly share code, notes, and snippets.

@03difoha
03difoha / 3.js
Last active September 21, 2019 06:49
function createArrayOfFunctions(y) {
var arr = [];
// fix: for (let i = 0; i < y; i++) {
for (var i = 0; i < y; i++) {
arr[i] = function (x) {
return x + i;
}
// if we run arr[i] immediately inside the loop, we get the desired function.
}
// The problem is that the i inside each generated function all increment with each iteration. (scope leaking)
@03difoha
03difoha / 2.js
Last active September 24, 2019 06:47
var ds = {
totalCapacity: 1000,
usedCapacity: 0,
items: {},
updateCapacity: function(){
this.usedCapacity = Object.values(this.items).reduce((t, {weight}) => t + weight, 0)
},
getItem: function (key) {
return this.items[key] ? this.items[key] : -1
},
@03difoha
03difoha / 1.js
Created September 19, 2019 03:09
function isSubset(list1, list2) {
let list2 = [...new Set(list2)];
let confirmed = 0
for (var l of list2) {
if (list1.includes(l)) {
confirmed++
}
}
return confirmed == list2.length
}

Keybase proof

I hereby claim:

  • I am 03difoha on github.
  • I am 03difoha (https://keybase.io/03difoha) on keybase.
  • I have a public key ASDJ6mmDCc1Ym1dKEbm5WLoLicQcYgIlIVDMsMOxotxvUQo

To claim this, I am signing this object: