Last active
August 11, 2017 12:14
-
-
Save robbiemu/4bb46fc330be323bb579cb1174ee25b7 to your computer and use it in GitHub Desktop.
results from my initial interview with Patriot consulting, and 1 night's sleep to realize that I could have shown a basic data structure
This file contains 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
//2. Remove duplicate characters from a string (ABCdeABCfg -> ABCdefg) | |
/* build a string by ensuring that it does not already have letters in before adding */ | |
function dedup (dupped) { | |
deduped = '' // start with an empty string | |
dupped | |
.split('') // get an array of letters from the input | |
.forEach(l => { // for every letter in the array | |
if(deduped.indexOf(l) === -1) // if the string we are building does not contain it | |
deduped += l // add it (only once) | |
}) | |
return deduped // return the built string | |
} | |
// or with Set | |
function dedupDS (dupped) { | |
const duplicatesArray = dupped.split('') | |
const intermediateSet = new Set(duplicatesArray) | |
const uniqueArray = Array.from(intermediateSet) | |
const dedupped = uniqueArray.join('') | |
return dedupped | |
} | |
const expect (message, value) => if(!value()) console.warn(message) | |
expect("it should handle a normal case with repeats: (ABCdeABCfg -> ABCdefg)", | |
() => dedup('ABCdeABCfg') === 'ABCdefg') | |
expect("if we give it nothing, we get nothing", | |
() => dedup('') === '') | |
// user name, age - backend api accepts the username, age and returns success or failure | |
<template><!-- vuejs component --> | |
<section class=usertx> | |
<form class=userInput> | |
<formgroup> | |
<input type=text name=name v-model=user.name required></input> | |
<label for=name>Name</label> | |
</formgroup> | |
<formgroup> | |
<input type=number name=age v-model=user.age :value=default_age required></input> | |
<label for=age>Age</label> | |
</formgroup> | |
<button @click=submit>Submit</button> | |
</form> | |
<vue-modal :response=response></vue-modal> | |
</section> | |
</template> | |
<script> | |
import {mapState} from 'vuex' | |
import {userMethods} from 'store/user' | |
import {ServerResponseModal} from './ServerResponseModal' | |
export default { | |
data () { | |
return { | |
default_age: 20 | |
} | |
}, | |
computed: { | |
mapState({ user: state => state.usermodel.user, | |
response: state => state.usermodel.lastTx.response | |
}), | |
}, | |
methods { | |
submit () { | |
if(this.verify()) | |
this.submitToServer() | |
}, | |
verify() { // ensure quality post | |
}, | |
...userMethods // submitToServer | |
}, | |
components { vue-modal: ServerResponseModal } | |
} | |
<script> | |
<style lang="scss" scoped> | |
@import '/styles/userstyling'; | |
// styling | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment