Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 3 Exercise solution #108

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Dolphin]
Timestamp=2020,3,15,12,57,31
Version=4

[Settings]
HiddenFilesShown=true
116 changes: 116 additions & 0 deletions .eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/** @format */

module.exports = {
extends: ["airbnb", "prettier", "prettier/react"],
parser: "babel-eslint",
parserOptions: {
ecmaVersion: 2020,
// Can I remove these now?
ecmaFeatures: {
impliedStrict: true,
classes: true
}
},
env: {
browser: true,
node: true,
jquery: true,
jest: true
},
rules: {
"no-debugger": 0,
"no-alert": 0,
"no-await-in-loop": 0,
"no-return-assign": ["error", "except-parens"],
"no-restricted-syntax": [
2,
"ForInStatement",
"LabeledStatement",
"WithStatement"
],
"no-unused-vars": [
1,
{
ignoreSiblings: true,
argsIgnorePattern: "res|next|^err"
}
],
"prefer-const": [
"error",
{
destructuring: "all"
}
],
"arrow-body-style": [2, "as-needed"],
"no-unused-expressions": [
2,
{
allowTaggedTemplates: true
}
],
"no-param-reassign": [
2,
{
props: false
}
],
"no-console": 0,
"import/prefer-default-export": 0,
import: 0,
"func-names": 0,
"space-before-function-paren": 0,
"comma-dangle": 0,
"max-len": 0,
"import/extensions": 0,
"no-underscore-dangle": 0,
"consistent-return": 0,
"react/display-name": 1,
"react/no-array-index-key": 0,
"react/react-in-jsx-scope": 0,
"react/prefer-stateless-function": 0,
"react/forbid-prop-types": 0,
"react/no-unescaped-entities": 0,
"jsx-a11y/accessible-emoji": 0,
"react/require-default-props": 0,
"react/jsx-filename-extension": [
1,
{
extensions: [".js", ".jsx"]
}
],
radix: 0,
"no-shadow": [
2,
{
hoist: "all",
allow: ["resolve", "reject", "done", "next", "err", "error"]
}
],
quotes: [
2,
"single",
{
avoidEscape: true,
allowTemplateLiterals: true
}
],
"prettier/prettier": [
"error",
{
trailingComma: "es5",
singleQuote: true,
printWidth: 80
}
],
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/anchor-is-valid": [
"warn",
{
aspects: ["invalidHref"]
}
],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
plugins: ["html", "prettier", "react-hooks"]
};
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "airbnb",
"env": {
"jest": true
},
"rules": {
"no-restricted-syntax": 0,
"arrow-parens": 0,
"import/prefer-default-export": 0,
"no-console": 2,
"prettier/prettier": [
"error",
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 8,
}
]
}
}
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["wesbos"]
}
1,903 changes: 1,898 additions & 5 deletions .vscode/settings.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions js-exercises/.directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Dolphin]
Timestamp=2020,3,15,12,44,55
Version=4

[Settings]
HiddenFilesShown=true
116 changes: 116 additions & 0 deletions js-exercises/.eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/** @format */

module.exports = {
extends: ["airbnb", "prettier", "prettier/react"],
parser: "babel-eslint",
parserOptions: {
ecmaVersion: 2020,
// Can I remove these now?
ecmaFeatures: {
impliedStrict: true,
classes: true
}
},
env: {
browser: true,
node: true,
jquery: true,
jest: true
},
rules: {
"no-debugger": 0,
"no-alert": 0,
"no-await-in-loop": 0,
"no-return-assign": ["error", "except-parens"],
"no-restricted-syntax": [
2,
"ForInStatement",
"LabeledStatement",
"WithStatement"
],
"no-unused-vars": [
1,
{
ignoreSiblings: true,
argsIgnorePattern: "res|next|^err"
}
],
"prefer-const": [
"error",
{
destructuring: "all"
}
],
"arrow-body-style": [2, "as-needed"],
"no-unused-expressions": [
2,
{
allowTaggedTemplates: true
}
],
"no-param-reassign": [
2,
{
props: false
}
],
"no-console": 0,
"import/prefer-default-export": 0,
import: 0,
"func-names": 0,
"space-before-function-paren": 0,
"comma-dangle": 0,
"max-len": 0,
"import/extensions": 0,
"no-underscore-dangle": 0,
"consistent-return": 0,
"react/display-name": 1,
"react/no-array-index-key": 0,
"react/react-in-jsx-scope": 0,
"react/prefer-stateless-function": 0,
"react/forbid-prop-types": 0,
"react/no-unescaped-entities": 0,
"jsx-a11y/accessible-emoji": 0,
"react/require-default-props": 0,
"react/jsx-filename-extension": [
1,
{
extensions: [".js", ".jsx"]
}
],
radix: 0,
"no-shadow": [
2,
{
hoist: "all",
allow: ["resolve", "reject", "done", "next", "err", "error"]
}
],
quotes: [
2,
"single",
{
avoidEscape: true,
allowTemplateLiterals: true
}
],
"prettier/prettier": [
"error",
{
trailingComma: "es5",
singleQuote: true,
printWidth: 80
}
],
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/anchor-is-valid": [
"warn",
{
aspects: ["invalidHref"]
}
],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
plugins: ["html", "prettier", "react-hooks"]
};
12 changes: 11 additions & 1 deletion js-exercises/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
"rules": {
"no-restricted-syntax": 0,
"arrow-parens": 0,
"import/prefer-default-export": 0
"import/prefer-default-export": 0,
"no-console": 2,
"prettier/prettier": [
"error",
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 8,
}
]
}
}
3 changes: 3 additions & 0 deletions js-exercises/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["wesbos"]
}
7 changes: 7 additions & 0 deletions js-exercises/abbreviate-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Instructions

- Given a string return the abbreviated version of the string

For example -

Given `Hacktober Fest` as the input the function should return `Hacktober F.`
31 changes: 31 additions & 0 deletions js-exercises/abbreviate-string/abbreviateString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Please be sincear and let me know about all the mistakes i have made
* please be a little kind as i am still a novoice and am still learning
* @Bhargav Mantha
*
* Procedure/Approach/psudo code i am following
* 1.now check if the input is a string or else return an error
* 2.split the input string into words
* 3.make the abbrivation return it
*/
const util = require('util');

const getWordsFromString = string => string.split(' ');
const checkIfString = string => util.isString(string);
function abbreviateString(string) {
const stringCondition = checkIfString(string);
let abbrivatedString = '';
if (stringCondition) {
const wordsArray = getWordsFromString(string);
abbrivatedString = `${wordsArray[0]} ${[
...wordsArray[wordsArray.length - 1],
][0].toUpperCase()}.`;
return abbrivatedString;
}
const error = new Error(
`Sorry. Could not eveluate the input.Reason the input was not a sting.expected string got <${typeof string}>`
);
throw error;
}
// console.log(abbreviateString('Leeroy Fitzgerald Jenkins'));
export { abbreviateString };
18 changes: 18 additions & 0 deletions js-exercises/abbreviate-string/abbreviateString.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { abbreviateString } from './abbreviateString';

describe('abbreviateString', () => {
it('abbreviates the following strings', () => {
expect(abbreviateString('Hacktober Fest')).toEqual('Hacktober F.');
expect(abbreviateString('Leeroy Fitzgerald Jenkins')).toEqual('Leeroy J.');
expect(abbreviateString('Some arbitrary string length here.')).toEqual(
'Some H.'
);
});

it('throws error on invalid parameters', () => {
expect(() => abbreviateString(123)).toThrow();
expect(() => abbreviateString([])).toThrow();
expect(() => abbreviateString({})).toThrow();
expect(() => abbreviateString(null)).toThrow();
});
});
17 changes: 17 additions & 0 deletions js-exercises/add-big-integers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Instructions

- Given a string with numbers separated by `\n`, return the sum of these numbers

For example -

```js
`539
8
201`;
```

// Add the numbers 539, 8 and 201

# Restrictions

- Don't use `BigInt` implementation of JavaScript.
Loading