summary refs log tree commit diff stats
path: root/javascript/square-root
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-08-25 20:10:19 +0530
committerAndinus <andinus@nand.sh>2021-08-25 20:10:19 +0530
commit3fb698bbe091cbaa8d5d3f2256ebfb776523448d (patch)
tree46afb9bc82dd810ef9b7b21ed15056721373fe18 /javascript/square-root
parent094df4feb1fc02197029764e4f748c9680150574 (diff)
downloadexercism-3fb698bbe091cbaa8d5d3f2256ebfb776523448d.tar.gz
JS: Solve hello-world, two-fer, square-root
Diffstat (limited to 'javascript/square-root')
-rw-r--r--javascript/square-root/.eslintrc29
-rw-r--r--javascript/square-root/.npmrc1
-rw-r--r--javascript/square-root/README.md61
-rw-r--r--javascript/square-root/babel.config.js15
-rw-r--r--javascript/square-root/package.json36
-rw-r--r--javascript/square-root/square-root.js3
-rw-r--r--javascript/square-root/square-root.spec.js22
7 files changed, 167 insertions, 0 deletions
diff --git a/javascript/square-root/.eslintrc b/javascript/square-root/.eslintrc
new file mode 100644
index 0000000..b8dab20
--- /dev/null
+++ b/javascript/square-root/.eslintrc
@@ -0,0 +1,29 @@
+{
+  "root": true,
+  "parser": "babel-eslint",
+  "parserOptions": {
+    "ecmaVersion": 7,
+    "sourceType": "module"
+  },
+  "globals": {
+    "BigInt": true
+  },
+  "env": {
+    "es6": true,
+    "node": true,
+    "jest": true
+  },
+  "extends": [
+    "eslint:recommended",
+    "plugin:import/errors",
+    "plugin:import/warnings"
+  ],
+  "rules": {
+    "linebreak-style": "off",
+
+    "import/extensions": "off",
+    "import/no-default-export": "off",
+    "import/no-unresolved": "off",
+    "import/prefer-default-export": "off"
+  }
+}
diff --git a/javascript/square-root/.npmrc b/javascript/square-root/.npmrc
new file mode 100644
index 0000000..d26df80
--- /dev/null
+++ b/javascript/square-root/.npmrc
@@ -0,0 +1 @@
+audit=false
diff --git a/javascript/square-root/README.md b/javascript/square-root/README.md
new file mode 100644
index 0000000..be243d3
--- /dev/null
+++ b/javascript/square-root/README.md
@@ -0,0 +1,61 @@
+# Square Root
+
+Given a natural radicand, return its square root.
+
+Note that the term "radicand" refers to the number for which the root is to be determined. That is, it is the number under the root symbol.
+
+Check out the Wikipedia pages on [square root](https://en.wikipedia.org/wiki/Square_root) and [methods of computing square roots](https://en.wikipedia.org/wiki/Methods_of_computing_square_roots).
+
+Recall also that natural numbers are positive real whole numbers (i.e. 1, 2, 3 and up).
+
+The idea is not to use the built-in javascript functions such as `Math.sqrt(x)`, `x ** 0.5` or `x ** (1/2)`, it's to build your own.
+
+
+## Setup
+
+Go through the setup instructions for Javascript to install the necessary
+dependencies:
+
+[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation)
+
+## Requirements
+
+Please `cd` into exercise directory before running all below commands.
+
+Install assignment dependencies:
+
+```bash
+$ npm install
+```
+
+## Making the test suite pass
+
+Execute the tests with:
+
+```bash
+$ npm test
+```
+
+In the test suites all tests but the first have been skipped.
+
+Once you get a test passing, you can enable the next one by changing `xtest` to
+`test`.
+
+
+## Submitting Solutions
+
+Once you have a solution ready, you can submit it using:
+
+```bash
+exercism submit square-root.js
+```
+
+## Submitting Incomplete Solutions
+
+It's possible to submit an incomplete solution so you can see how others have
+completed the exercise.
+
+## Exercise Source Credits
+
+wolf99 [https://github.com/exercism/problem-specifications/pull/1582](https://github.com/exercism/problem-specifications/pull/1582)
+
diff --git a/javascript/square-root/babel.config.js b/javascript/square-root/babel.config.js
new file mode 100644
index 0000000..5cec972
--- /dev/null
+++ b/javascript/square-root/babel.config.js
@@ -0,0 +1,15 @@
+module.exports = {
+  presets: [
+    [
+      '@babel/preset-env',
+      {
+        targets: {
+          node: 'current',
+        },
+        useBuiltIns: 'entry',
+        corejs: 3,
+      },
+    ],
+  ],
+  plugins: ['@babel/plugin-syntax-bigint'],
+};
diff --git a/javascript/square-root/package.json b/javascript/square-root/package.json
new file mode 100644
index 0000000..90f82c9
--- /dev/null
+++ b/javascript/square-root/package.json
@@ -0,0 +1,36 @@
+{
+  "name": "@exercism/javascript",
+  "description": "Exercism exercises in Javascript.",
+  "author": "Katrina Owen",
+  "private": true,
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/exercism/javascript"
+  },
+  "devDependencies": {
+    "@babel/cli": "^7.12.10",
+    "@babel/core": "^7.12.10",
+    "@babel/plugin-syntax-bigint": "^7.8.3",
+    "@babel/preset-env": "^7.12.11",
+    "@types/jest": "^26.0.19",
+    "@types/node": "^14.14.14",
+    "babel-eslint": "^10.1.0",
+    "babel-jest": "^26.6.3",
+    "core-js": "^3.8.1",
+    "eslint": "^7.15.0",
+    "eslint-plugin-import": "^2.22.1",
+    "jest": "^26.6.3"
+  },
+  "jest": {
+    "modulePathIgnorePatterns": [
+      "package.json"
+    ]
+  },
+  "scripts": {
+    "test": "jest --no-cache ./*",
+    "watch": "jest --no-cache --watch ./*",
+    "lint": "eslint ."
+  },
+  "license": "MIT",
+  "dependencies": {}
+}
diff --git a/javascript/square-root/square-root.js b/javascript/square-root/square-root.js
new file mode 100644
index 0000000..50c3634
--- /dev/null
+++ b/javascript/square-root/square-root.js
@@ -0,0 +1,3 @@
+export const squareRoot = (num) => {
+    return Math.sqrt(num);
+};
diff --git a/javascript/square-root/square-root.spec.js b/javascript/square-root/square-root.spec.js
new file mode 100644
index 0000000..3db6fcb
--- /dev/null
+++ b/javascript/square-root/square-root.spec.js
@@ -0,0 +1,22 @@
+import { squareRoot } from './square-root';
+
+describe('Square root', () => {
+    test('root of 1', () => {
+        expect(squareRoot(1)).toEqual(1);
+    });
+    test('root of 4', () => {
+        expect(squareRoot(4)).toEqual(2);
+    });
+    test('root of 5', () => {
+        expect(squareRoot(25)).toEqual(5);
+    });
+    test('root of 81', () => {
+        expect(squareRoot(81)).toEqual(9);
+    });
+    test('root of 196', () => {
+        expect(squareRoot(196)).toEqual(14);
+    });
+    test('root of 65025', () => {
+        expect(squareRoot(65025)).toEqual(255);
+    });
+});