Skip to content

Instantly share code, notes, and snippets.

View odino's full-sized avatar
shipping!

Alessandro Nadalin odino

shipping!
View GitHub Profile
@odino
odino / desc.md
Last active December 17, 2021 14:32

Coding challenge: cartified!

Hey JavaScript talents, here at namshi.com, we are looking for you! Submit this coding challenge to alex.nadalin@namshi.com and we'll get back to you as soon as possible!

Your task is to implement a basic shopping cart for a website, following these basic rules:

  • the cart needs to be implemented as an AngularJS service
  • the cart should be retrieved from the localStorage, where it's stored under the key cart
  • every time an action is performed on the cart, it should be persisted on the localStorage
  • the cart should only know about item IDs and their quantity
SGVsbG8gd29ybGQK
app.get("/my-view", async (req, res) => {
res.send(render("my-view", {data: await db.getData()}))
})
function render(view, ctx = {}) {
return _.template(fs.readFileSync(`./views/${view}.html`))(ctx)
}
token = env("GH_TOKEN")
no_more_repos = false
page = 1
while !no_more_repos {
repos = `curl -s -H "Authorization: token $token" "https://api.github.com/orgs/namshi/repos?page=$page&type=private"`.json()
if !repos.len() {
no_more_repos = true
echo("End of repositories!")
class DumbMap {
constructor() {
this.list = []
}
get(x) {
let result
this.list.forEach(pairs => {
if (pairs[0] === x) {
a=new AudioContext() // browsers limit the number of concurrent audio contexts, so you better re-use'em
function beep(vol, freq, duration){
v=a.createOscillator()
u=a.createGain()
v.connect(u)
v.frequency.value=freq
v.type="square"
u.connect(a.destination)
u.gain.value=vol*0.01
class DumbMap {
constructor() {
this.list = []
}
get(x) {
let i = hash(x)
if (!this.list[i]) {
return undefined
let m = new DumbMap()
for (x = 0; x < 1000000; x++) {
m.set(`element${x}`, x)
}
console.log(m.get('element0')) // 999988
console.log(m.get('element1')) // 999988
console.log(m.get('element1000')) // 999987
function divide(int) {
int = Math.round(int / 2)
if (int > 10) {
return divide(int)
}
return int
}
let m = new DumbMap()
m.set('x', 1)
m.set('y', 2)
console.time('with very few records in the map')
m.get('I_DONT_EXIST')
console.timeEnd('with very few records in the map')
m = new DumbMap()