-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
818d1ce
commit 164188f
Showing
6 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Eric Beecroft/wk11 - starts 16th May/1-mon/yegge-interview-questions/index.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<html> | ||
<head> | ||
<title>Nail that Interview!</title> | ||
<meta charset="utf-8"> | ||
</head> | ||
|
||
<body> | ||
<p> | ||
Please check the Javascript console for output. | ||
</p> | ||
|
||
<script src="js/exercises.js"></script> | ||
</body> | ||
</html> |
81 changes: 81 additions & 0 deletions
81
Eric Beecroft/wk11 - starts 16th May/1-mon/yegge-interview-questions/js/exercises.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
console.log('Steve Yegge Coding Test Questions') | ||
|
||
console.log('1. Write a function to reverse a string.') | ||
|
||
function reverse(string) { | ||
// let array = string.split('') | ||
// let flip = array.reverse() | ||
// let join = flip.join('') | ||
// console.log(join) | ||
|
||
const reversed = string.split('').reverse().join('') | ||
console.log(reversed) | ||
} | ||
|
||
reverse('this is a test') | ||
|
||
/////// | ||
|
||
console.log('Write function to compute Nth fibonacci number:') | ||
|
||
function fibonacci(n) { | ||
if (n <= 1) | ||
return n; | ||
return fibonacci(n-1) + fibonacci(n-2); | ||
} | ||
|
||
console.log(fibonacci(8)) | ||
|
||
/////// | ||
|
||
console.log('Print out the grade-school multiplication table up to 12x12') | ||
|
||
const table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | ||
|
||
function timestables(n) { | ||
table.forEach(element => { | ||
const result = n * element | ||
console.log(result) | ||
}); | ||
}; | ||
|
||
timestables(2); | ||
|
||
//////// | ||
|
||
console.log('Write function to print the odd numbers from 1 to 99.') | ||
|
||
const oddNums = () => { | ||
for ( let i = 1; i < 100; i++ ) { | ||
if ( i % 2 !== 0 ) { | ||
console.log(i) | ||
} | ||
} | ||
}; | ||
|
||
oddNums(); | ||
|
||
//////// | ||
|
||
console.log('Find the largest int value in an int array.') | ||
|
||
const data = [4, 5, 7, 9, 11, 23, 2, 21]; | ||
|
||
const largest = (array) => { | ||
array.sort((a, b) => b - a); | ||
console.log(`The largest value in [${data}] is ${ array[0] }`); | ||
}; | ||
|
||
largest(data); | ||
|
||
//////// | ||
|
||
console.log('Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.') | ||
|
||
const rgbToHex = (r, g, b) => '#' + [r, g, b].map(x => { | ||
const hex = x.toString(16) // converts the number to hexadecimals | ||
return hex.length === 1 ? '0' + hex : hex // If hex.length === 0 return 0+hex (eg. hex = 1 return 01) else return hex | ||
}).join('') | ||
|
||
console.log(rgbToHex(0, 51, 255)); // #0033ff | ||
console.log(rgbToHex(52, 235, 103)); // #34eb67 |
16 changes: 16 additions & 0 deletions
16
Eric Beecroft/wk11 - starts 16th May/1-mon/yegge-interview-questions/js/fizzbuzz.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
console.log('Create a for loop that iterates up to 100 while outputting "fizz" at multiples of 3, "buzz" at multiples of 5 and "fizzbuzz" at multiples of 3 and 5') | ||
|
||
const fizzbuzz = () => { | ||
for ( let i = 1; i < 101; i++ ) { | ||
console.log(i); | ||
if (i % 3 === 0 && i % 5 === 0) { | ||
console.log('fizzbuzz') | ||
} else if ( i % 3 === 0) { | ||
console.log('fizz') | ||
} else if ( i % 5 === 0) { | ||
console.log('buzz') | ||
} | ||
} | ||
}; | ||
|
||
fizzbuzz(); |
1 change: 1 addition & 0 deletions
1
Eric Beecroft/wk11 - starts 16th May/1-mon/yegge-interview-questions/numbers.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 2 3 4 5 6 7 8 9 |
12 changes: 12 additions & 0 deletions
12
Eric Beecroft/wk11 - starts 16th May/1-mon/yegge-interview-questions/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "00-interview-questions", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
15 changes: 15 additions & 0 deletions
15
Eric Beecroft/wk11 - starts 16th May/1-mon/yegge-interview-questions/sum.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Write a function that sums up integers from a text file, one int per line. | ||
|
||
const fs = require('fs'); | ||
|
||
fs.readFile('numbers.txt', 'utf-8', function (error, data) { | ||
if (error) { | ||
return console.error(error); // a bit wanky | ||
} | ||
const initialValue = 0; | ||
const array = data.split(' ') | ||
const nums = array.map((array) => parseInt(array)); | ||
const sum = nums.reduce((a, b) => a + b, initialValue); | ||
|
||
console.log(sum); | ||
}); |