Skip to content

Commit

Permalink
Training
Browse files Browse the repository at this point in the history
  • Loading branch information
ebeecroft1 committed May 16, 2022
1 parent 818d1ce commit 164188f
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 0 deletions.
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>
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
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();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 3 4 5 6 7 8 9
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"
}
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);
});

0 comments on commit 164188f

Please sign in to comment.