├── File-System ├── file-utilities │ ├── short.txt │ └── file-name-from-path.js └── file-name-from-path │ └── nameFromPath.js ├── _Extra-Practice ├── free-code-camp │ ├── nodejs │ │ ├── http-collect.js │ │ ├── hello.js │ │ ├── hello-world.js │ │ ├── add.js │ │ ├── baby-steps-add-args.js │ │ ├── first-io-count-newlines.js │ │ ├── count-newlines.js │ │ ├── first-async-count-newlines.js │ │ ├── make-modular-program.js │ │ └── http-client.js │ ├── README.md │ ├── basic-algorithm │ │ ├── 11-slasher-flick-slice.js │ │ ├── 01-reverse-a-string.js │ │ ├── 13-falsy-bouncer.js │ │ ├── 08-repeat-a-string.js │ │ ├── 02-factorialize.js │ │ ├── 15-where-do-i-belong.js │ │ └── 07-confirm-ending.js │ └── intermediate-algorithm │ │ ├── 15-finders-keepers.js │ │ ├── 17-steamroller.js │ │ ├── 11-spinal-tap-case.js │ │ └── 08-boo-hoo-booleans.js ├── binarySearchExample-master │ ├── .gitignore │ └── .DS_Store ├── binaryTreeExample-master │ └── .gitignore ├── binarySearchRecursionExample-master │ └── .gitignore ├── 30-days-of-code-master │ ├── day10_binary.py │ ├── day5_loops.py │ ├── day6_review.py │ ├── day9_recursion.py │ ├── day2_operators.py │ └── day7_arrays.py └── README.md ├── Arrays ├── All Unique │ └── test │ │ └── scrap.md ├── array-helpers │ └── flatten-arrays.js └── basic-examples │ └── problems │ ├── reverse-string.js │ ├── my-map.js │ └── number-fun.js ├── General-Interview-Prep ├── freecodecamp │ └── basic │ │ ├── 16-fruits.js │ │ └── 18-boo-hoo.js ├── algoexpert │ └── easy │ │ └── 04-linked-list.js └── geeksforgeeks │ └── README.md ├── modules ├── package.json ├── package-lock.json └── module-aggregation │ └── modules │ └── shapes.js ├── renovate.json ├── Graphs ├── graphs-intro-solution │ └── node_modules │ │ ├── chai │ │ ├── CODEOWNERS │ │ ├── index.js │ │ ├── register-assert.js │ │ ├── register-expect.js │ │ └── register-should.js │ │ └── chai-spies │ │ └── index.js ├── graph_project │ └── lib │ │ └── graph_node.js ├── bonus-graph-project │ └── lib │ │ └── graph_node.js └── graphs-solution │ └── problems │ └── graph_node.js ├── Dynamic-Programming └── dynamic-time-warping │ ├── index.js │ └── lib │ └── distanceFunctions │ ├── manhattan.js │ ├── euclidean.js │ └── squaredEuclidean.js ├── ALGO ├── shortestWord.js ├── spiral │ ├── input-1.png │ └── input-2.png ├── stringAddition.js ├── linked-list │ └── Readme.md ├── queue │ └── Readme.md ├── stack │ └── Readme.md ├── UNSORTED │ ├── string-rotation.js │ ├── reverse-words-in-string.js │ ├── shortest-fizz-buzz.js │ ├── odd-occuring-element.js │ ├── integer-length.js │ ├── Sum-of-series.js │ ├── Sum-multiples-of 3 and 5.js │ ├── Factorial.js │ ├── string-format.js │ ├── Recursion-countdown.js │ ├── CopyMachine.js │ ├── remove-duplicates-from-string.js │ └── prime-number.js ├── merge-sort │ └── Readme.md ├── quick-sort │ └── Readme.md ├── computational-complexity │ ├── O(2^n).js │ ├── O(log(n)).js │ ├── O(n!).js │ └── O(n^2).js ├── MinHeap │ └── min_heap_example.jpg ├── insertion-sort │ └── README.md ├── selection-sort │ └── readme.md ├── number-format │ └── Readme.md ├── prime-number │ └── Readme.md ├── reverse-words-in-string │ └── reverse-words-in-string.js ├── integer-length │ ├── Readme.md │ └── integer-length.js ├── digitize.js ├── odd-occuring-element │ └── odd-occuring-element.js ├── typedarray │ ├── typedarray-reverse.js │ ├── typedarray-from.js │ ├── typedarray-name.js │ ├── typedarray-sort.js │ ├── typedarray-map.js │ ├── typedarray-bytes-per-element.js │ ├── typedarray-slice.js │ ├── typedarray-of.js │ ├── typedarray-tostring.js │ ├── typedarray-fill.js │ ├── typedarray-keys.js │ ├── typedarray-length.js │ ├── typedarray-bytelength.js │ ├── typedarray-buffer.js │ ├── typedarray-entries.js │ ├── typedarray-values.js │ ├── typedarray-lastindexof.js │ ├── typedarray-every.js │ ├── typedarray-reduce.js │ ├── typedarray-find.js │ ├── typedarray-findindex.js │ ├── typedarray-includes.js │ ├── typedarray-subarray.js │ ├── typedarray-copywithin.js │ ├── typedarray-filter.js │ ├── typedarray-join.js │ ├── typedarray-indexof.js │ └── typedarray-set.js ├── factorial.py ├── sorted-array-search │ └── Readme.md ├── missing-number │ └── Readme.md ├── odd_even_numbers.py ├── number_game.py ├── symbol │ ├── symbol-hasinstance.js │ ├── symbol-iterator.js │ ├── symbol-tostringtag.js │ ├── symbol-matchall.js │ ├── symbol-toprimitive.js │ ├── symbol-unscopables.js │ ├── symbol-search.js │ ├── symbol-replace.js │ └── symbol-for.js ├── money-format │ └── Readme.md ├── multiplesoffiveandthree.js ├── __PYTHON │ ├── kth_largest.py │ ├── xor.py │ ├── fib_series.py │ ├── exists_in.py │ ├── wave.py │ ├── once.py │ └── prime-number.py ├── sum-of-array-plus-one │ └── Readme.md ├── fibonacci │ └── fibonacci-memo.js ├── factorial.js ├── flatten-array │ ├── es5.js │ ├── in-place.js │ └── copy.js ├── largest-palindrome │ └── Readme.md ├── once │ └── Readme.md ├── string-rotation │ └── Readme.md ├── weakmap │ ├── weakmap-prototype-delete.js │ ├── weakmap-prototype-get.js │ ├── weakmap-prototype-has.js │ └── weakmap-prototype-set.js ├── squareofnumber.js ├── weakset │ ├── weakset-prototype-has.js │ └── weakset-prototype-delete.js ├── memoization_project │ └── test │ │ └── util.js ├── bmi.py ├── longest-common-prefix │ └── Readme.md ├── search-unknown-length-array │ └── Readme.md ├── permutation.py ├── remove-duplicates-from-string │ └── remove-duplicates-from-string.js ├── reverse-a-string.js └── spinal-tap-case.js ├── string ├── string-fromcharcode.js ├── string-codepointat.js ├── string-fromcodepoint.js ├── string-substr.js ├── string-length.js ├── string-substring.js ├── string-tolowercase.js ├── string-touppercase.js ├── string-tostring.js ├── string-valueof.js ├── string-trim.js ├── string-startswith.js ├── string-trimend.js ├── string-trimstart.js ├── string-tolocaleuppercase.js ├── string-concat.js ├── string-match.js ├── string-charat.js ├── string-endswith.js ├── string-padend.js ├── string-tolocalelowercase.js ├── string-includes.js ├── string-charcodeat.js ├── string-localecompare.js ├── string-matchall.js └── string-raw.js ├── Numbers_Math ├── xor.js ├── is-prime.js └── euclidean-distance │ └── euclidian-dist.js ├── web-dev ├── events │ ├── demo.gif │ └── Capture.PNG └── convert-2-js-arr │ └── multi-2-arr.css ├── Google-FooBar-master ├── README.md ├── status.JPG ├── Capture2.JPG ├── Capture3.JPG ├── Capture4.JPG ├── Capture-level-4.JPG ├── E │ ├── Presentation1.jpg │ ├── Presentation1.pptx │ ├── Expanding Nebula.docx │ ├── Expanding Nebula.pdf │ └── __pycache__ │ │ ├── MSEA.cpython-35.pyc │ │ ├── lkup2.cpython-35.pyc │ │ ├── NK_MANSON.cpython-35.pyc │ │ ├── test_nebula.cpython-35.pyc │ │ └── My_Expanding_Nebula.cpython-35.pyc ├── Master_FooBar.PNG ├── google-foobar.gif ├── shoemaker_vare.pdf ├── Screenshot (625).png └── foobar3.py ├── boolean ├── boolean-constructor.js ├── boolean-valueof.js └── boolean-tostring.js ├── Misc ├── set-utils │ ├── inSet.js │ └── check-subset.js └── data-structures-html-spec-runner │ └── .eslintignore ├── POJOs ├── obj2Array │ └── obj2Array.PNG ├── extend-obj-prop │ └── extend-obj-prop.js └── objPropMap │ └── obj-prop-map.js ├── Trees ├── Binary-Search-Tree │ ├── 2.png │ ├── 3.png │ ├── a1.png │ ├── ya.png │ ├── b-vs-trda.png │ ├── bst-mid-ele.png │ ├── findMin.js │ └── getHeight.js ├── levelwidth │ └── node.js └── tree_order_project │ └── lib │ └── tree_node.js ├── promises-test └── myLittleVader.jpg ├── array ├── array-tostring.js ├── array-length.js ├── array-find.js ├── array-from.js ├── array-unshift.js ├── array-findindex.js ├── array-map.js ├── array-foreach.js ├── array-every.js ├── array-some.js ├── array-concat.js ├── array-lastindexof.js ├── array-shift.js ├── array-keys.js ├── array-reduce-right.js ├── array-flat.js ├── array-values.js ├── array-entries.js ├── array-iterator.js ├── array-join.js ├── array-includes.js ├── array-sort.js ├── array-tolocalestring.js ├── array-reduce.js ├── array-filter.js └── array-indexof.js ├── Recursion ├── lucas-num-versions │ ├── naive-lucasnum.js │ ├── memo-lucasnum.js │ └── tab-lucasnum.js ├── fibonacci-versions │ ├── memo-fibonacci.js │ ├── naive-fibonacci.js │ └── tab-fibonacci.js ├── binary-search │ └── binary-search.js └── recursion_project │ └── test │ └── util.js ├── date ├── date-gethours.js ├── date-getminutes.js ├── date-getseconds.js ├── date-getfullyear.js ├── date-getutcseconds.js ├── date-getdate.js ├── date-getmonth.js ├── date-toutcstring.js ├── date-getday.js ├── date-getmilliseconds.js ├── date-totimestring.js ├── date-getutcmilliseconds.js ├── date-tostring.js ├── date-gettime.js ├── date-setutcdate.js ├── date-setmilliseconds.js ├── date-setutcminutes.js ├── date-setutcseconds.js ├── date-getutcdate.js ├── date-parse.js ├── date-setutcmilliseconds.js ├── date-setmonth.js ├── date-getutchours.js ├── date-setfullyear.js ├── date-todatestring.js ├── date-valueof.js ├── date-setseconds.js ├── date-toisostring.js ├── date-getutcfullyear.js ├── date-setdate.js ├── date-setminutes.js ├── date-tojson.js ├── date-getutcday.js ├── date-utc.js ├── date-getutcmonth.js └── date-getutcminutes.js ├── expressions ├── expressions-logical-and.js ├── expressions-logical-not.js ├── expressions-functionexpression.js ├── expressions-left-shift-assignment.js ├── expressions-commaoperators.js ├── expressions-logical-and-assignment.js ├── expressions-addition-assignment.js ├── expressions-bitwise-and-assignment.js ├── expressions-bitwise-or-assignment.js ├── expressions-bitwise-or.js ├── expressions-bitwise-xor-assignment.js ├── expressions-bitwise-and.js ├── expressions-bitwise-xor.js ├── expressions-left-shift.js ├── expressions-division-assignment.js ├── expressions-exponentiation-assignment.js ├── expressions-bitwise-not.js ├── expressions-assignment.js ├── expressions-decrement.js ├── expressions-increment.js ├── expressions-division.js ├── expressions-greater-than.js ├── expressions-less-than.js ├── expressions-functionasteriskexpression.js ├── expressions-equality.js ├── expressions-exponentiation.js ├── expressions-less-than-or-equal.js ├── expressions-greater-than-or-equal.js ├── expressions-inequality.js ├── expressions-deleteoperator.js ├── expressions-destructuringassignment.js ├── expressions-groupingoperator.js ├── expressions-classexpression.js ├── expressions-addition.js ├── expressions-inoperator.js └── expressions-conditionaloperators.js ├── statement ├── statement-while.js ├── statement-for.js ├── statement-function.js ├── statement-break.js ├── statement-class.js ├── statement-let.js ├── statement-var.js ├── statement-dowhile.js ├── statement-block.js ├── statement-forof.js ├── statement-continue.js ├── statement-empty.js ├── statement-label.js ├── statement-forin.js ├── statement-trycatch.js ├── statement-ifelse.js ├── statement-functionasterisk.js ├── statement-return.js ├── statement-throw.js └── statement-const.js ├── knapsack └── data │ ├── small1.txt │ ├── small2.txt │ └── small3.txt ├── math ├── math-ln2.js ├── math-log2e.js ├── math-sqrt2.js ├── math-ln10.js ├── math-log10e.js ├── math-sqrt1_2.js ├── math-max.js ├── math-min.js ├── math-pi.js ├── math-sign.js ├── math-ceil.js ├── math-cbrt.js ├── math-floor.js ├── math-log.js ├── math-round.js ├── math-log2.js ├── math-trunc.js ├── math-log10.js ├── math-log1p.js ├── math-hypot.js ├── math-imul.js ├── math-tanh.js ├── math-abs.js ├── math-acosh.js ├── math-atanh.js ├── math-expm1.js ├── math-fround.js ├── math-sinh.js ├── math-asinh.js ├── math-exp.js ├── math-sqrt.js ├── math-acos.js ├── math-asin.js ├── math-atan2.js ├── math-clz32.js ├── math-pow.js ├── math-atan.js └── math-random.js ├── makefile ├── intl ├── intl-prototype-@@tostringtag.js ├── intl-collator-supportedlocalesof.js ├── intl-collator-prototype-resolvedoptions.js ├── intl-numberformat-supportedlocalesof.js └── intl-datetimeformat-supportedlocalesof.js ├── map ├── map-prototype-@@tostringtag.js ├── map-prototype-size.js ├── map-prototype-has.js ├── map-prototype-get.js ├── map-prototype-set.js ├── map-prototype-clear.js ├── map-prototype-delete.js ├── map-prototype-keys.js ├── map-prototype-values.js ├── map-prototype-entries.js └── map-prototype-@@iterator.js ├── SANDBOX ├── leet_code_110.js ├── 06-leet-code-450.js ├── leet_code_108.js ├── 05-leet-code-108.js ├── leet_code_64.js ├── leet_code_70.js ├── 04-leet-code-110.js ├── nim-game.js ├── powx-n.js ├── leet_code_105.js ├── move-zeroes.js ├── valid-number.js ├── sort-colors.js ├── bulb-switcher.js ├── power-of-two.js ├── palindrome-number.js ├── reverse-string.js ├── sqrtx.js ├── implement-strstr.js ├── find-minimum-in-rotated-sorted-array.js ├── find-minimum-in-rotated-sorted-array-ii.js ├── detect-capital.js └── arranging-coins.js ├── functions ├── functions-definitions.js ├── functions-default.js ├── functions-arrow.js ├── functions-setter.js ├── functions-arguments.js ├── functions-getter.js └── functions-restparameters.js ├── bigint ├── bigint-valueof.js └── bigint-tostring.js ├── promise ├── promise-resolve.js ├── promise-catch.js ├── promise-then.js └── promise-reject.js ├── editable-samples ├── editor │ └── codemirror │ │ └── theme │ │ └── ambiance-mobile.css └── repl │ ├── array-slice │ └── array-slice.js │ └── pages │ └── array-push │ └── array-push.js ├── 0-TESTING-RESOURCES └── main-data │ └── output.txt ├── MINI-DS-PROJECtS ├── graph_project │ └── lib │ │ └── graph_node.js ├── depth_breadth_first_project │ └── lib │ │ ├── tree_sum.js │ │ └── tree_node.js ├── tree_order_project │ └── lib │ │ └── tree_node.js ├── memoization_project │ └── test │ │ └── util.js └── recursion_project │ └── test │ └── util.js ├── _COMMON-DS-CLASSES └── models │ └── list-node.js ├── arraybuffer ├── arraybuffer-constructor.js ├── arraybuffer-isview.js └── arraybuffer-bytelength.js ├── object ├── object-keys.js ├── object-getprototypeof.js ├── object-getownpropertynames.js ├── object-values.js ├── object-freeze.js ├── object-fromentries.js ├── object-isextensible.js ├── object-issealed.js ├── object-isfrozen.js ├── object-defineproperties.js ├── object-prototype-valueof.js ├── object-defineproperty.js ├── object-entries.js ├── object-prototype-tostring.js ├── object-getownpropertydescriptor.js ├── object-seal.js ├── object-assign.js ├── object-getownpropertydescriptors.js ├── object-getownpropertysymbols.js └── object-prototype-tolocalestring.js ├── Complete-Projects ├── 20_graph_project │ └── lib │ │ └── graph_node.js ├── 18_depth_breadth_first_project │ └── lib │ │ ├── tree_height.js │ │ └── tree_node.js ├── 01_recursion_project │ └── test │ │ └── util.js └── 02_memoization_project │ └── test │ └── util.js ├── regexp ├── regexp-prototype-flags.js ├── regexp-prototype-dotall.js ├── regexp-prototype-global.js ├── regexp-prototype-@@replace.js ├── regexp-constructor.js ├── regexp-lastindex.js ├── regexp-prototype-@@search.js └── regexp-prototype-source.js ├── sharedarraybuffer ├── sharedarraybuffer-bytelength.js └── sharedarraybuffer-constructor.js ├── Utilities-Snippets └── general │ └── arrEq.js ├── json └── json-parse.js ├── number ├── number-epsilon.js ├── number-isfinite.js ├── number-nan.js ├── number-valueof.js ├── number-tostring.js ├── number-isinteger.js ├── number-isnan.js ├── number-toexponential.js ├── number-max-safe-integer.js ├── number-min-safe-integer.js ├── number-tofixed.js ├── number-toprecision.js └── number-tolocalestring.js ├── globalprops ├── globalprops-globalthis.js ├── globalprops-null.js ├── globalprops-undefined.js ├── globalprops-nan.js ├── globalprops-encodeuricomponent.js ├── globalprops-infinity.js ├── globalprops-isnan.js ├── globalprops-parseint.js └── globalprops-isfinite.js ├── dataview ├── dataview-buffer.js ├── dataview-byteoffset.js ├── dataview-getfloat32.js ├── dataview-getfloat64.js ├── dataview-getint8.js ├── dataview-setfloat32.js ├── dataview-setfloat64.js ├── dataview-setint8.js ├── dataview-getuint8.js ├── dataview-setuint8.js ├── dataview-getint16.js ├── dataview-setint16.js ├── dataview-getuint16.js ├── dataview-setuint16.js ├── dataview-getint32.js ├── dataview-setint32.js ├── dataview-getuint32.js ├── dataview-setuint32.js └── dataview-bytelength.js ├── Binary-Trees ├── levelwidth │ └── node.js └── tree_order_project │ └── lib │ └── tree_node.js ├── classes └── classes-constructor.js ├── set ├── set-prototype-clear.js ├── set-prototype-size.js ├── set-prototype-add.js ├── set-prototype-has.js ├── set-prototype-constructor.js ├── set-prototype-values.js ├── set-prototype-entries.js ├── set-prototype-delete.js ├── set-prototype-@@iterator.js └── set-prototype-foreach.js ├── Strings └── python │ └── reverse-word │ └── rev-word.py ├── Sorting-n-Searching └── 1-searching-algorithms │ └── depth_breadth_first_project │ └── lib │ ├── tree_height.js │ └── tree_node.js ├── atomics ├── atomics-islockfree.js └── atomics-store.js ├── reflect ├── reflect-get.js ├── reflect-preventextensions.js ├── reflect-getprototypeof.js ├── reflect-set.js ├── reflect-ownkeys.js └── reflect-has.js └── Fifo-Lifo └── Queue └── qfroms └── stack.js /File-System/file-utilities/short.txt: -------------------------------------------------------------------------------- 1 | one 2 | two 3 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/http-collect.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Arrays/All Unique/test/scrap.md: -------------------------------------------------------------------------------- 1 | ./../all-unique.js 2 | -------------------------------------------------------------------------------- /General-Interview-Prep/freecodecamp/basic/16-fruits.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /modules/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["config:base"] 3 | } 4 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/README.md: -------------------------------------------------------------------------------- 1 | # freeCodeCamp 2 | -------------------------------------------------------------------------------- /modules/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1 3 | } 4 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/hello.js: -------------------------------------------------------------------------------- 1 | console.log("HELLO WORLD"); 2 | -------------------------------------------------------------------------------- /Graphs/graphs-intro-solution/node_modules/chai/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @chaijs/chai 2 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/hello-world.js: -------------------------------------------------------------------------------- 1 | console.log("HELLO WORLD"); 2 | -------------------------------------------------------------------------------- /Dynamic-Programming/dynamic-time-warping/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/dtw"); 2 | -------------------------------------------------------------------------------- /_Extra-Practice/binarySearchExample-master/.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | /node_modules 3 | -------------------------------------------------------------------------------- /_Extra-Practice/binaryTreeExample-master/.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | /node_modules 3 | -------------------------------------------------------------------------------- /Graphs/graphs-intro-solution/node_modules/chai/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require( './lib/chai' ); 2 | -------------------------------------------------------------------------------- /_Extra-Practice/binarySearchRecursionExample-master/.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | /node_modules 3 | -------------------------------------------------------------------------------- /ALGO/shortestWord.js: -------------------------------------------------------------------------------- 1 | function findShort(s){ 2 | return Math.min(...s.split(" ").map(s => s.length)); 3 | } -------------------------------------------------------------------------------- /Graphs/graphs-intro-solution/node_modules/chai-spies/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require( './lib/spy' ); 2 | -------------------------------------------------------------------------------- /Graphs/graphs-intro-solution/node_modules/chai/register-assert.js: -------------------------------------------------------------------------------- 1 | global.assert = require( './' ).assert; 2 | -------------------------------------------------------------------------------- /Graphs/graphs-intro-solution/node_modules/chai/register-expect.js: -------------------------------------------------------------------------------- 1 | global.expect = require( './' ).expect; 2 | -------------------------------------------------------------------------------- /Graphs/graphs-intro-solution/node_modules/chai/register-should.js: -------------------------------------------------------------------------------- 1 | global.should = require( './' ).should(); 2 | -------------------------------------------------------------------------------- /string/string-fromcharcode.js: -------------------------------------------------------------------------------- 1 | console.log(String.fromCharCode(189, 43, 190, 61)); 2 | // expected output: "½+¾=" 3 | -------------------------------------------------------------------------------- /ALGO/spiral/input-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/ALGO/spiral/input-1.png -------------------------------------------------------------------------------- /ALGO/spiral/input-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/ALGO/spiral/input-2.png -------------------------------------------------------------------------------- /ALGO/stringAddition.js: -------------------------------------------------------------------------------- 1 | function joinStrings(string1, string2){ 2 | return `${string1} ${string2}`; 3 | // code here 4 | } -------------------------------------------------------------------------------- /Numbers_Math/xor.js: -------------------------------------------------------------------------------- 1 | let XOR = function (a, b) { 2 | if ((a || b) && !(a && b)) { 3 | return true; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /web-dev/events/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/web-dev/events/demo.gif -------------------------------------------------------------------------------- /ALGO/linked-list/Readme.md: -------------------------------------------------------------------------------- 1 | # Linked List 2 | 3 | Write a linked list implementation, better yet - make it doubly linked. 4 | -------------------------------------------------------------------------------- /ALGO/queue/Readme.md: -------------------------------------------------------------------------------- 1 | # Basic Queue 2 | 3 | Implement a basic queue function with the ability to `add` and `remove` values. 4 | -------------------------------------------------------------------------------- /ALGO/stack/Readme.md: -------------------------------------------------------------------------------- 1 | # Basic Stack 2 | 3 | Implement a basic stack function with the ability to `add` and `remove` values. 4 | -------------------------------------------------------------------------------- /Google-FooBar-master/README.md: -------------------------------------------------------------------------------- 1 | # Google-FooBar 2 | Questions & Codes asked in all levels of Google FooBar coding challenge 3 | -------------------------------------------------------------------------------- /boolean/boolean-constructor.js: -------------------------------------------------------------------------------- 1 | const flag = new Boolean(); 2 | 3 | console.log(flag); 4 | // expected output: false 5 | -------------------------------------------------------------------------------- /web-dev/events/Capture.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/web-dev/events/Capture.PNG -------------------------------------------------------------------------------- /ALGO/UNSORTED/string-rotation.js: -------------------------------------------------------------------------------- 1 | export default (a, b) => { 2 | return a.length === b.length && (a + a).includes(b); 3 | }; 4 | -------------------------------------------------------------------------------- /ALGO/merge-sort/Readme.md: -------------------------------------------------------------------------------- 1 | # Merge Sort 2 | 3 | Implement the [merge sort algorithm](http://en.wikipedia.org/wiki/Merge_sort). 4 | -------------------------------------------------------------------------------- /ALGO/quick-sort/Readme.md: -------------------------------------------------------------------------------- 1 | # Quick Sort 2 | 3 | Implement the [quick sort algorithm](http://en.wikipedia.org/wiki/Quicksort). 4 | -------------------------------------------------------------------------------- /Misc/set-utils/inSet.js: -------------------------------------------------------------------------------- 1 | find = (set, fn) => { 2 | for (const item of set) { 3 | if (fn(item)) return item; 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /POJOs/obj2Array/obj2Array.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/POJOs/obj2Array/obj2Array.PNG -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Trees/Binary-Search-Tree/2.png -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Trees/Binary-Search-Tree/3.png -------------------------------------------------------------------------------- /string/string-codepointat.js: -------------------------------------------------------------------------------- 1 | const icons = '☃★♲'; 2 | 3 | console.log(icons.codePointAt(1)); 4 | // expected output: "9733" 5 | -------------------------------------------------------------------------------- /string/string-fromcodepoint.js: -------------------------------------------------------------------------------- 1 | console.log(String.fromCodePoint(9731, 9733, 9842, 0x2F804)); 2 | // expected output: "☃★♲你" 3 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/reverse-words-in-string.js: -------------------------------------------------------------------------------- 1 | export default (string) => { 2 | return string.split(/\s+/g).reverse().join(" "); 3 | }; 4 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/shortest-fizz-buzz.js: -------------------------------------------------------------------------------- 1 | for (i = 0; ++i < 101; ) 2 | console.log((i % 3 ? "" : "Fizz") + (i % 5 ? "" : "Buzz") || i); 3 | -------------------------------------------------------------------------------- /ALGO/computational-complexity/O(2^n).js: -------------------------------------------------------------------------------- 1 | const twoN = (n) => { 2 | if (n == 1) return n; 3 | twoN(n - 1); 4 | twoN(n - 1); 5 | }; 6 | -------------------------------------------------------------------------------- /Google-FooBar-master/status.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/status.JPG -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/a1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Trees/Binary-Search-Tree/a1.png -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/ya.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Trees/Binary-Search-Tree/ya.png -------------------------------------------------------------------------------- /promises-test/myLittleVader.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/promises-test/myLittleVader.jpg -------------------------------------------------------------------------------- /ALGO/MinHeap/min_heap_example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/ALGO/MinHeap/min_heap_example.jpg -------------------------------------------------------------------------------- /ALGO/computational-complexity/O(log(n)).js: -------------------------------------------------------------------------------- 1 | const splitInHalf = (n) => { 2 | if (n <= 1) return n; 3 | return splitInHalf(n / 2); 4 | }; 5 | -------------------------------------------------------------------------------- /Google-FooBar-master/Capture2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/Capture2.JPG -------------------------------------------------------------------------------- /Google-FooBar-master/Capture3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/Capture3.JPG -------------------------------------------------------------------------------- /Google-FooBar-master/Capture4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/Capture4.JPG -------------------------------------------------------------------------------- /array/array-tostring.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 2, 'a', '1a']; 2 | 3 | console.log(array1.toString()); 4 | // expected output: "1,2,a,1a" 5 | -------------------------------------------------------------------------------- /ALGO/insertion-sort/README.md: -------------------------------------------------------------------------------- 1 | # Insertion Sort 2 | 3 | Implement the [insertion sort algorithm](http://en.wikipedia.org/wiki/Insertion_sort). 4 | -------------------------------------------------------------------------------- /ALGO/selection-sort/readme.md: -------------------------------------------------------------------------------- 1 | # Selection Sort 2 | 3 | Implement the [selection sort algorithm](http://en.wikipedia.org/wiki/Selection_sort). 4 | -------------------------------------------------------------------------------- /Recursion/lucas-num-versions/naive-lucasnum.js: -------------------------------------------------------------------------------- 1 | function lucas(n) { 2 | return n === 1 ? 2 : n === 2 ? 1 : lucas(n - 1) + fib(n - 2); 3 | } 4 | -------------------------------------------------------------------------------- /date/date-gethours.js: -------------------------------------------------------------------------------- 1 | const birthday = new Date('March 13, 08 04:20'); 2 | 3 | console.log(birthday.getHours()); 4 | // expected output: 4 5 | -------------------------------------------------------------------------------- /expressions/expressions-logical-and.js: -------------------------------------------------------------------------------- 1 | const a = 3; 2 | const b = -2; 3 | 4 | console.log(a > 0 && b > 0); 5 | // expected output: false 6 | -------------------------------------------------------------------------------- /statement/statement-while.js: -------------------------------------------------------------------------------- 1 | let n = 0; 2 | 3 | while (n < 3) { 4 | n++; 5 | } 6 | 7 | console.log(n); 8 | // expected output: 3 9 | -------------------------------------------------------------------------------- /ALGO/number-format/Readme.md: -------------------------------------------------------------------------------- 1 | # Numeric String 2 | 3 | Format any number into a string with "," (commas) in the correct places. E.g. "1,000,000". 4 | -------------------------------------------------------------------------------- /ALGO/prime-number/Readme.md: -------------------------------------------------------------------------------- 1 | # Prime Number 2 | 3 | Write a function that accepts a number and return a boolean based on whether it's a prime number. 4 | -------------------------------------------------------------------------------- /ALGO/reverse-words-in-string/reverse-words-in-string.js: -------------------------------------------------------------------------------- 1 | module.exports = (string) => { 2 | return string.split(/\s+/g).reverse().join(" "); 3 | }; 4 | -------------------------------------------------------------------------------- /Google-FooBar-master/Capture-level-4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/Capture-level-4.JPG -------------------------------------------------------------------------------- /Google-FooBar-master/E/Presentation1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/Presentation1.jpg -------------------------------------------------------------------------------- /Google-FooBar-master/Master_FooBar.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/Master_FooBar.PNG -------------------------------------------------------------------------------- /Google-FooBar-master/google-foobar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/google-foobar.gif -------------------------------------------------------------------------------- /Google-FooBar-master/shoemaker_vare.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/shoemaker_vare.pdf -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/b-vs-trda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Trees/Binary-Search-Tree/b-vs-trda.png -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/bst-mid-ele.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Trees/Binary-Search-Tree/bst-mid-ele.png -------------------------------------------------------------------------------- /array/array-length.js: -------------------------------------------------------------------------------- 1 | const clothing = ['shoes', 'shirts', 'socks', 'sweaters']; 2 | 3 | console.log(clothing.length); 4 | // expected output: 4 5 | -------------------------------------------------------------------------------- /date/date-getminutes.js: -------------------------------------------------------------------------------- 1 | const birthday = new Date('March 13, 08 04:20'); 2 | 3 | console.log(birthday.getMinutes()); 4 | // expected output: 20 5 | -------------------------------------------------------------------------------- /expressions/expressions-logical-not.js: -------------------------------------------------------------------------------- 1 | const a = 3; 2 | const b = -2; 3 | 4 | console.log(!(a > 0 || b > 0)); 5 | // expected output: false 6 | -------------------------------------------------------------------------------- /ALGO/integer-length/Readme.md: -------------------------------------------------------------------------------- 1 | # Integer Length 2 | 3 | Write a function that takes an integer as input and returns the number of digits in that integer. 4 | -------------------------------------------------------------------------------- /Google-FooBar-master/E/Presentation1.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/Presentation1.pptx -------------------------------------------------------------------------------- /Google-FooBar-master/Screenshot (625).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/Screenshot (625).png -------------------------------------------------------------------------------- /knapsack/data/small1.txt: -------------------------------------------------------------------------------- 1 | 1 42 81 2 | 2 42 42 3 | 3 68 56 4 | 4 68 25 5 | 5 77 14 6 | 6 57 63 7 | 7 17 75 8 | 8 19 41 9 | 9 94 19 10 | 10 34 12 11 | -------------------------------------------------------------------------------- /knapsack/data/small2.txt: -------------------------------------------------------------------------------- 1 | 1 18 100 2 | 2 51 76 3 | 3 68 26 4 | 4 44 79 5 | 5 46 64 6 | 6 65 18 7 | 7 66 1 8 | 8 52 80 9 | 9 47 93 10 | 10 3 66 11 | -------------------------------------------------------------------------------- /knapsack/data/small3.txt: -------------------------------------------------------------------------------- 1 | 1 95 18 2 | 2 67 19 3 | 3 77 5 4 | 4 21 26 5 | 5 22 15 6 | 6 74 64 7 | 7 22 28 8 | 8 92 18 9 | 9 7 60 10 | 10 63 21 11 | -------------------------------------------------------------------------------- /math/math-ln2.js: -------------------------------------------------------------------------------- 1 | function getNatLog2() { 2 | return Math.LN2; 3 | } 4 | 5 | console.log(getNatLog2()); 6 | // expected output: 0.6931471805599453 7 | -------------------------------------------------------------------------------- /math/math-log2e.js: -------------------------------------------------------------------------------- 1 | function getLog2e() { 2 | return Math.LOG2E; 3 | } 4 | 5 | console.log(getLog2e()); 6 | // expected output: 1.4426950408889634 7 | -------------------------------------------------------------------------------- /math/math-sqrt2.js: -------------------------------------------------------------------------------- 1 | function getRoot2() { 2 | return Math.SQRT2; 3 | } 4 | 5 | console.log(getRoot2()); 6 | // expected output: 1.4142135623730951 7 | -------------------------------------------------------------------------------- /Google-FooBar-master/E/Expanding Nebula.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/Expanding Nebula.docx -------------------------------------------------------------------------------- /Google-FooBar-master/E/Expanding Nebula.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/Expanding Nebula.pdf -------------------------------------------------------------------------------- /_Extra-Practice/30-days-of-code-master/day10_binary.py: -------------------------------------------------------------------------------- 1 | 2 | binarystr = max([len(x) for x in bin(int(input()))[2:].split('0')]) 3 | 4 | print(binarystr) 5 | -------------------------------------------------------------------------------- /date/date-getseconds.js: -------------------------------------------------------------------------------- 1 | const moonLanding = new Date('July 20, 69 00:20:18'); 2 | 3 | console.log(moonLanding.getSeconds()); 4 | // expected output: 18 5 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | git: 2 | git add . 3 | git commit -m "$m-update" 4 | git push -u origin master 5 | # just type make into the terminal to exicute these commands! 6 | -------------------------------------------------------------------------------- /math/math-ln10.js: -------------------------------------------------------------------------------- 1 | function getNatLog10() { 2 | return Math.LN10; 3 | } 4 | 5 | console.log(getNatLog10()); 6 | // expected output: 2.302585092994046 7 | -------------------------------------------------------------------------------- /math/math-log10e.js: -------------------------------------------------------------------------------- 1 | function getLog10e() { 2 | return Math.LOG10E; 3 | } 4 | 5 | console.log(getLog10e()); 6 | // expected output: 0.4342944819032518 7 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/odd-occuring-element.js: -------------------------------------------------------------------------------- 1 | export default (array) => { 2 | return array.reduce((memo, number) => { 3 | return memo ^ number; 4 | }, 0); 5 | }; 6 | -------------------------------------------------------------------------------- /date/date-getfullyear.js: -------------------------------------------------------------------------------- 1 | const moonLanding = new Date('July 20, 69 00:20:18'); 2 | 3 | console.log(moonLanding.getFullYear()); 4 | // expected output: 1969 5 | -------------------------------------------------------------------------------- /intl/intl-prototype-@@tostringtag.js: -------------------------------------------------------------------------------- 1 | const intl1 = Object.prototype.toString.call(Intl); 2 | 3 | console.log(intl1); 4 | // expected output: "[object Intl]" 5 | -------------------------------------------------------------------------------- /map/map-prototype-@@tostringtag.js: -------------------------------------------------------------------------------- 1 | const map1 = Object.prototype.toString.call(new Map()); 2 | 3 | console.log(map1); 4 | // expected output: "[object Map]" 5 | -------------------------------------------------------------------------------- /date/date-getutcseconds.js: -------------------------------------------------------------------------------- 1 | const moonLanding = new Date('July 20, 1969, 20:18:04 UTC'); 2 | 3 | console.log(moonLanding.getUTCSeconds()); 4 | // expected output: 4 5 | -------------------------------------------------------------------------------- /math/math-sqrt1_2.js: -------------------------------------------------------------------------------- 1 | function getRoot1Over2() { 2 | return Math.SQRT1_2; 3 | } 4 | 5 | console.log(getRoot1Over2()); 6 | // expected output: 0.7071067811865476 7 | -------------------------------------------------------------------------------- /web-dev/convert-2-js-arr/multi-2-arr.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 25px; 3 | } 4 | #input { 5 | height: 150px; 6 | font-family: "Courier New", Courier, monospace; 7 | } 8 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/integer-length.js: -------------------------------------------------------------------------------- 1 | export default (num) => { 2 | // There is an extra check here to ensure the number is an integer 3 | return `${num | 0}`.length; 4 | }; 5 | -------------------------------------------------------------------------------- /ALGO/computational-complexity/O(n!).js: -------------------------------------------------------------------------------- 1 | const factorial = (n) => { 2 | if (n === 1) return n; 3 | for (let i = 0; i < n; i++) { 4 | factorial(n - 1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /ALGO/digitize.js: -------------------------------------------------------------------------------- 1 | function digitize(n) { 2 | r = n.toString().split(''); 3 | r.forEach((el, i, a) => { a[i] = parseInt(el); }) 4 | return r 5 | } 6 | digitize(123) 7 | -------------------------------------------------------------------------------- /SANDBOX/leet_code_110.js: -------------------------------------------------------------------------------- 1 | // View the full problem and run the test cases at: 2 | // https://leetcode.com/problems/balanced-binary-tree/ 3 | 4 | function isBalanced(root) {} 5 | -------------------------------------------------------------------------------- /_Extra-Practice/binarySearchExample-master/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/_Extra-Practice/binarySearchExample-master/.DS_Store -------------------------------------------------------------------------------- /date/date-getdate.js: -------------------------------------------------------------------------------- 1 | const birthday = new Date('August 19, 1975 23:15:30'); 2 | const date1 = birthday.getDate(); 3 | 4 | console.log(date1); 5 | // expected output: 19 6 | -------------------------------------------------------------------------------- /date/date-getmonth.js: -------------------------------------------------------------------------------- 1 | const moonLanding = new Date('July 20, 69 00:20:18'); 2 | 3 | console.log(moonLanding.getMonth()); // (January gives 0) 4 | // expected output: 6 5 | -------------------------------------------------------------------------------- /functions/functions-definitions.js: -------------------------------------------------------------------------------- 1 | const obj = { 2 | foo() { 3 | return 'bar'; 4 | } 5 | }; 6 | 7 | console.log(obj.foo()); 8 | // expected output: "bar" 9 | -------------------------------------------------------------------------------- /ALGO/odd-occuring-element/odd-occuring-element.js: -------------------------------------------------------------------------------- 1 | module.exports = (array) => { 2 | return array.reduce((memo, number) => { 3 | return memo ^ number; 4 | }, 0); 5 | }; 6 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-reverse.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([1, 2, 3]); 2 | uint8.reverse(); 3 | 4 | console.log(uint8); 5 | // expected output: Uint8Array [3, 2, 1] 6 | -------------------------------------------------------------------------------- /Google-FooBar-master/E/__pycache__/MSEA.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/__pycache__/MSEA.cpython-35.pyc -------------------------------------------------------------------------------- /Google-FooBar-master/E/__pycache__/lkup2.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/__pycache__/lkup2.cpython-35.pyc -------------------------------------------------------------------------------- /_Extra-Practice/30-days-of-code-master/day5_loops.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | n = int(input().strip()) 5 | 6 | for i in range(10): 7 | print(n,'x',i+1,'=',(n*(i+1))) 8 | -------------------------------------------------------------------------------- /bigint/bigint-valueof.js: -------------------------------------------------------------------------------- 1 | console.log(typeof Object(1n)); 2 | // expected output: "object" 3 | 4 | console.log(typeof Object(1n).valueOf()); 5 | // expected output: "bigint" 6 | -------------------------------------------------------------------------------- /date/date-toutcstring.js: -------------------------------------------------------------------------------- 1 | const event = new Date('14 Jun 2017 00:00:00 PDT'); 2 | 3 | console.log(event.toUTCString()); 4 | // expected output: Wed, 14 Jun 2017 07:00:00 GMT 5 | -------------------------------------------------------------------------------- /promise/promise-resolve.js: -------------------------------------------------------------------------------- 1 | const promise1 = Promise.resolve(123); 2 | 3 | promise1.then((value) => { 4 | console.log(value); 5 | // expected output: 123 6 | }); 7 | 8 | -------------------------------------------------------------------------------- /statement/statement-for.js: -------------------------------------------------------------------------------- 1 | let str = ''; 2 | 3 | for (let i = 0; i < 9; i++) { 4 | str = str + i; 5 | } 6 | 7 | console.log(str); 8 | // expected output: "012345678" 9 | -------------------------------------------------------------------------------- /ALGO/integer-length/integer-length.js: -------------------------------------------------------------------------------- 1 | module.exports = (num) => { 2 | // There is an extra check here to ensure the number is an integer 3 | return ("" + (num | 0)).length; 4 | }; 5 | -------------------------------------------------------------------------------- /Misc/data-structures-html-spec-runner/.eslintignore: -------------------------------------------------------------------------------- 1 | .eslint* 2 | **/node_modules 3 | **/bower_components 4 | **/lib 5 | **/vendor 6 | **/*.min.js 7 | sprint-one/spec/verifyClass.js 8 | -------------------------------------------------------------------------------- /SANDBOX/06-leet-code-450.js: -------------------------------------------------------------------------------- 1 | // View the full problem and run the test cases at: 2 | // https://leetcode.com/problems/delete-node-in-a-bst/ 3 | 4 | function deleteNode(root, key) {} 5 | -------------------------------------------------------------------------------- /array/array-find.js: -------------------------------------------------------------------------------- 1 | const array1 = [5, 12, 8, 130, 44]; 2 | 3 | const found = array1.find((element) => element > 10); 4 | 5 | console.log(found); 6 | // expected output: 12 7 | -------------------------------------------------------------------------------- /editable-samples/editor/codemirror/theme/ambiance-mobile.css: -------------------------------------------------------------------------------- 1 | .cm-s-ambiance.CodeMirror { 2 | -webkit-box-shadow: none; 3 | -moz-box-shadow: none; 4 | box-shadow: none; 5 | } 6 | -------------------------------------------------------------------------------- /statement/statement-function.js: -------------------------------------------------------------------------------- 1 | function calcRectArea(width, height) { 2 | return width * height; 3 | } 4 | 5 | console.log(calcRectArea(5, 6)); 6 | // expected output: 30 7 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/Sum-of-series.js: -------------------------------------------------------------------------------- 1 | function sum(a, b) { 2 | function fn(x) { 3 | return 1 / (x * x); 4 | } 5 | let s = 0; 6 | for (; a <= b; a++) s += fn(a); 7 | return s; 8 | } 9 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-from.js: -------------------------------------------------------------------------------- 1 | let uint16 = new Int16Array; 2 | uint16 = Int16Array.from('12345'); 3 | 4 | console.log(uint16); 5 | // expected output: Int16Array [1, 2, 3, 4, 5] 6 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-name.js: -------------------------------------------------------------------------------- 1 | console.log(Uint8Array.name); 2 | // expected output: "Uint8Array" 3 | 4 | console.log(Float32Array.name); 5 | // expected output: "Float32Array" 6 | -------------------------------------------------------------------------------- /Google-FooBar-master/E/__pycache__/NK_MANSON.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/__pycache__/NK_MANSON.cpython-35.pyc -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/11-slasher-flick-slice.js: -------------------------------------------------------------------------------- 1 | function slasher(arr, howMany) { 2 | return arr.slice(howMany); 3 | } 4 | 5 | console.log(slasher([1, 2, 3], 2)); 6 | -------------------------------------------------------------------------------- /ALGO/factorial.py: -------------------------------------------------------------------------------- 1 | # Find the factorial of a user input (intiger) 2 | number = int(input("Enter a number: ")) 3 | x = 1 4 | 5 | for index in range(number, 0, -1): 6 | x *= index 7 | print(x ) -------------------------------------------------------------------------------- /ALGO/sorted-array-search/Readme.md: -------------------------------------------------------------------------------- 1 | # Sorted Array Search 2 | 3 | Given an array of numbers sorted in ascending order, write a function that will return the index at which the number is found. 4 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-sort.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([40, 10, 50, 20, 30]); 2 | uint8.sort(); 3 | 4 | console.log(uint8); 5 | // expected output: Uint8Array [10, 20, 30, 40, 50] 6 | -------------------------------------------------------------------------------- /Google-FooBar-master/E/__pycache__/test_nebula.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/__pycache__/test_nebula.cpython-35.pyc -------------------------------------------------------------------------------- /Numbers_Math/is-prime.js: -------------------------------------------------------------------------------- 1 | let isPrime = (num) => { 2 | if (num < 2) return false; 3 | for (i = 2; i < num; i++) { 4 | if (num % i === 0) return false; 5 | } 6 | return true; 7 | }; 8 | -------------------------------------------------------------------------------- /modules/module-aggregation/modules/shapes.js: -------------------------------------------------------------------------------- 1 | export { Square } from './shapes/square.js'; 2 | export { Triangle } from './shapes/triangle.js'; 3 | export { Circle } from './shapes/circle.js'; 4 | -------------------------------------------------------------------------------- /string/string-substr.js: -------------------------------------------------------------------------------- 1 | const str = 'Mozilla'; 2 | 3 | console.log(str.substr(1, 2)); 4 | // expected output: "oz" 5 | 6 | console.log(str.substr(2)); 7 | // expected output: "zilla" 8 | -------------------------------------------------------------------------------- /0-TESTING-RESOURCES/main-data/output.txt: -------------------------------------------------------------------------------- 1 | 01-Person-Data.txt,cities.txt,city-state-country.txt,common-surnames.txt,dates.txt,html-colors.txt,street-names.txt,test-data.md,test.js,testdata.js,zip-codes.txt -------------------------------------------------------------------------------- /ALGO/UNSORTED/Sum-multiples-of 3 and 5.js: -------------------------------------------------------------------------------- 1 | function sumMults(n) { 2 | let sum = 0; 3 | for (let i = 1; i < n; i++) { 4 | if (i % 3 == 0 || i % 5 == 0) sum += i; 5 | } 6 | return sum; 7 | } 8 | -------------------------------------------------------------------------------- /ALGO/missing-number/Readme.md: -------------------------------------------------------------------------------- 1 | # Missing Number 2 | 3 | Write a function that accepts an array of integers in random order of unknown length, but with one number missing. Return the missing number. 4 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-map.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([25, 36, 49]); 2 | const roots = uint8.map(Math.sqrt); 3 | 4 | console.log(roots); 5 | // expected output: Uint8Array [5, 6, 7] 6 | -------------------------------------------------------------------------------- /MINI-DS-PROJECtS/graph_project/lib/graph_node.js: -------------------------------------------------------------------------------- 1 | class GraphNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.neighbors = []; 5 | } 6 | } 7 | 8 | module.exports = { GraphNode }; 9 | -------------------------------------------------------------------------------- /_COMMON-DS-CLASSES/models/list-node.js: -------------------------------------------------------------------------------- 1 | class ListNode { 2 | constructor(data, next = null) { 3 | this.data = data; 4 | this.next = next; 5 | } 6 | } 7 | 8 | module.exports = ListNode; 9 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/add.js: -------------------------------------------------------------------------------- 1 | const numbers = process.argv.slice(2); 2 | 3 | const total = numbers.reduce((done, curr) => Number(done) + Number(curr)); 4 | 5 | console.log(total); 6 | -------------------------------------------------------------------------------- /arraybuffer/arraybuffer-constructor.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(8); 3 | 4 | console.log(buffer.byteLength); 5 | // expected output: 8 6 | -------------------------------------------------------------------------------- /object/object-keys.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | a: 'somestring', 3 | b: 42, 4 | c: false 5 | }; 6 | 7 | console.log(Object.keys(object1)); 8 | // expected output: Array ["a", "b", "c"] 9 | -------------------------------------------------------------------------------- /ALGO/computational-complexity/O(n^2).js: -------------------------------------------------------------------------------- 1 | const dreadedDubs = (li) => { 2 | for (let i = 0; i < li.length; i++) { 3 | for (let j = 0; j < li.length; j++) { 4 | print(j); 5 | } 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-bytes-per-element.js: -------------------------------------------------------------------------------- 1 | console.log(Float64Array.BYTES_PER_ELEMENT); 2 | // expected output: 8 3 | 4 | console.log(Int8Array.BYTES_PER_ELEMENT); 5 | // expected output: 1 6 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-slice.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | const array1 = uint8.slice(1, 3); 3 | 4 | console.log(array1); 5 | // expected output: Uint8Array [20, 30] 6 | -------------------------------------------------------------------------------- /Complete-Projects/20_graph_project/lib/graph_node.js: -------------------------------------------------------------------------------- 1 | class GraphNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.neighbors = []; 5 | } 6 | } 7 | 8 | module.exports = { GraphNode }; 9 | -------------------------------------------------------------------------------- /SANDBOX/leet_code_108.js: -------------------------------------------------------------------------------- 1 | // View the full problem and run the test cases at: 2 | // https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 3 | 4 | function sortedArrayToBST(nums) {} 5 | -------------------------------------------------------------------------------- /array/array-from.js: -------------------------------------------------------------------------------- 1 | console.log(Array.from('foo')); 2 | // expected output: Array ["f", "o", "o"] 3 | 4 | console.log(Array.from([1, 2, 3], (x) => x + x)); 5 | // expected output: Array [2, 4, 6] 6 | -------------------------------------------------------------------------------- /array/array-unshift.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 2, 3]; 2 | 3 | console.log(array1.unshift(4, 5)); 4 | // expected output: 5 5 | 6 | console.log(array1); 7 | // expected output: Array [4, 5, 1, 2, 3] 8 | -------------------------------------------------------------------------------- /date/date-getday.js: -------------------------------------------------------------------------------- 1 | const birthday = new Date('August 19, 1975 23:15:30'); 2 | const day1 = birthday.getDay(); 3 | // Sunday - Saturday : 0 - 6 4 | 5 | console.log(day1); 6 | // expected output: 2 7 | -------------------------------------------------------------------------------- /expressions/expressions-functionexpression.js: -------------------------------------------------------------------------------- 1 | const getRectArea = function(width, height) { 2 | return width * height; 3 | }; 4 | 5 | console.log(getRectArea(3, 4)); 6 | // expected output: 12 7 | -------------------------------------------------------------------------------- /map/map-prototype-size.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | 3 | map1.set('a', 'alpha'); 4 | map1.set('b', 'beta'); 5 | map1.set('g', 'gamma'); 6 | 7 | console.log(map1.size); 8 | // expected output: 3 9 | -------------------------------------------------------------------------------- /object/object-getprototypeof.js: -------------------------------------------------------------------------------- 1 | const prototype1 = {}; 2 | const object1 = Object.create(prototype1); 3 | 4 | console.log(Object.getPrototypeOf(object1) === prototype1); 5 | // expected output: true 6 | -------------------------------------------------------------------------------- /string/string-length.js: -------------------------------------------------------------------------------- 1 | const str = 'Life, the universe and everything. Answer:'; 2 | 3 | console.log(`${str} ${str.length}`); 4 | // expected output: "Life, the universe and everything. Answer: 42" 5 | -------------------------------------------------------------------------------- /string/string-substring.js: -------------------------------------------------------------------------------- 1 | const str = 'Mozilla'; 2 | 3 | console.log(str.substring(1, 3)); 4 | // expected output: "oz" 5 | 6 | console.log(str.substring(2)); 7 | // expected output: "zilla" 8 | -------------------------------------------------------------------------------- /ALGO/odd_even_numbers.py: -------------------------------------------------------------------------------- 1 | # Input any number to know if its an odd or even number 2 | 3 | x = int(input("Check number")) 4 | if (x % 2 == 0): 5 | print(x, " is even") 6 | else: 7 | print(x, " is odd") 8 | -------------------------------------------------------------------------------- /Google-FooBar-master/E/__pycache__/My_Expanding_Nebula.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgoonz/Data-Structures-Algos-Codebase/HEAD/Google-FooBar-master/E/__pycache__/My_Expanding_Nebula.cpython-35.pyc -------------------------------------------------------------------------------- /SANDBOX/05-leet-code-108.js: -------------------------------------------------------------------------------- 1 | // View the full problem and run the test cases at: 2 | // https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 3 | 4 | function sortedArrayToBST(nums) {} 5 | -------------------------------------------------------------------------------- /array/array-findindex.js: -------------------------------------------------------------------------------- 1 | const array1 = [5, 12, 8, 130, 44]; 2 | 3 | const isLargeNumber = (element) => element > 13; 4 | 5 | console.log(array1.findIndex(isLargeNumber)); 6 | // expected output: 3 7 | -------------------------------------------------------------------------------- /array/array-map.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 4, 9, 16]; 2 | 3 | // pass a function to map 4 | const map1 = array1.map((x) => x * 2); 5 | 6 | console.log(map1); 7 | // expected output: Array [2, 8, 18, 32] 8 | -------------------------------------------------------------------------------- /date/date-getmilliseconds.js: -------------------------------------------------------------------------------- 1 | const moonLanding = new Date('July 20, 69 00:20:18'); 2 | moonLanding.setMilliseconds(123); 3 | 4 | console.log(moonLanding.getMilliseconds()); 5 | // expected output: 123 6 | -------------------------------------------------------------------------------- /expressions/expressions-left-shift-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 5; // 00000000000000000000000000000101 2 | 3 | a <<= 2; // 00000000000000000000000000010100 4 | 5 | console.log(a); 6 | // expected output: 20 7 | -------------------------------------------------------------------------------- /object/object-getownpropertynames.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | a: 1, 3 | b: 2, 4 | c: 3 5 | }; 6 | 7 | console.log(Object.getOwnPropertyNames(object1)); 8 | // expected output: Array ["a", "b", "c"] 9 | -------------------------------------------------------------------------------- /object/object-values.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | a: 'somestring', 3 | b: 42, 4 | c: false 5 | }; 6 | 7 | console.log(Object.values(object1)); 8 | // expected output: Array ["somestring", 42, false] 9 | -------------------------------------------------------------------------------- /statement/statement-break.js: -------------------------------------------------------------------------------- 1 | let i = 0; 2 | 3 | while (i < 6) { 4 | if (i === 3) { 5 | break; 6 | } 7 | i = i + 1; 8 | } 9 | 10 | console.log(i); 11 | // expected output: 3 12 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-of.js: -------------------------------------------------------------------------------- 1 | let uint16 = new Int16Array; 2 | uint16 = Int16Array.of('10', '20', '30', '40', '50'); 3 | 4 | console.log(uint16); 5 | // expected output: Int16Array [10, 20, 30, 40, 50] 6 | -------------------------------------------------------------------------------- /Graphs/graph_project/lib/graph_node.js: -------------------------------------------------------------------------------- 1 | class GraphNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.neighbors = []; 5 | } 6 | } 7 | 8 | module.exports = { 9 | GraphNode, 10 | }; 11 | -------------------------------------------------------------------------------- /POJOs/extend-obj-prop/extend-obj-prop.js: -------------------------------------------------------------------------------- 1 | export function extendObj(a, b) { 2 | for (const prop in b) { 3 | if (hasOwnProperty(b, prop)) { 4 | a[prop] = b[prop]; 5 | } 6 | } 7 | return a; 8 | } 9 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/baby-steps-add-args.js: -------------------------------------------------------------------------------- 1 | const numbers = process.argv.slice(2); 2 | 3 | const total = numbers.reduce((done, curr) => Number(done) + Number(curr)); 4 | 5 | console.log(total); 6 | -------------------------------------------------------------------------------- /array/array-foreach.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | 3 | array1.forEach((element) => console.log(element)); 4 | 5 | // expected output: "a" 6 | // expected output: "b" 7 | // expected output: "c" 8 | -------------------------------------------------------------------------------- /arraybuffer/arraybuffer-isview.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | console.log(ArrayBuffer.isView(new Int32Array())); 5 | // expected output: true 6 | -------------------------------------------------------------------------------- /date/date-totimestring.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | console.log(event.toTimeString()); 4 | // expected output: 23:15:30 GMT+0200 (CEST) 5 | // (note: your timezone may vary) 6 | -------------------------------------------------------------------------------- /statement/statement-class.js: -------------------------------------------------------------------------------- 1 | class Polygon { 2 | constructor(height, width) { 3 | this.area = height * width; 4 | } 5 | } 6 | 7 | console.log(new Polygon(4, 3).area); 8 | // expected output: 12 9 | -------------------------------------------------------------------------------- /statement/statement-let.js: -------------------------------------------------------------------------------- 1 | let x = 1; 2 | 3 | if (x === 1) { 4 | let x = 2; 5 | 6 | console.log(x); 7 | // expected output: 2 8 | } 9 | 10 | console.log(x); 11 | // expected output: 1 12 | -------------------------------------------------------------------------------- /statement/statement-var.js: -------------------------------------------------------------------------------- 1 | var x = 1; 2 | 3 | if (x === 1) { 4 | var x = 2; 5 | 6 | console.log(x); 7 | // expected output: 2 8 | } 9 | 10 | console.log(x); 11 | // expected output: 2 12 | -------------------------------------------------------------------------------- /string/string-tolowercase.js: -------------------------------------------------------------------------------- 1 | const sentence = 'The quick brown fox jumps over the lazy dog.'; 2 | 3 | console.log(sentence.toLowerCase()); 4 | // expected output: "the quick brown fox jumps over the lazy dog." 5 | -------------------------------------------------------------------------------- /string/string-touppercase.js: -------------------------------------------------------------------------------- 1 | const sentence = 'The quick brown fox jumps over the lazy dog.'; 2 | 3 | console.log(sentence.toUpperCase()); 4 | // expected output: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG." 5 | -------------------------------------------------------------------------------- /Graphs/bonus-graph-project/lib/graph_node.js: -------------------------------------------------------------------------------- 1 | class GraphNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.neighbors = []; 5 | } 6 | } 7 | 8 | module.exports = { 9 | GraphNode, 10 | }; 11 | -------------------------------------------------------------------------------- /Graphs/graphs-solution/problems/graph_node.js: -------------------------------------------------------------------------------- 1 | class GraphNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.neighbors = []; 5 | } 6 | } 7 | 8 | module.exports = { 9 | GraphNode, 10 | }; 11 | -------------------------------------------------------------------------------- /Numbers_Math/euclidean-distance/euclidian-dist.js: -------------------------------------------------------------------------------- 1 | let distance = function (x, y) { 2 | let difference = x - y; 3 | let euclideanDistance = Math.sqrt(difference * difference); 4 | return euclideanDistance; 5 | }; 6 | -------------------------------------------------------------------------------- /date/date-getutcmilliseconds.js: -------------------------------------------------------------------------------- 1 | const exampleDate = new Date('2018-01-02T03:04:05.678Z'); // 2 January 2018, 03:04:05.678 (UTC) 2 | 3 | console.log(exampleDate.getUTCMilliseconds()); 4 | // expected output: 678 5 | -------------------------------------------------------------------------------- /promise/promise-catch.js: -------------------------------------------------------------------------------- 1 | const promise1 = new Promise((resolve, reject) => { 2 | throw 'Uh-oh!'; 3 | }); 4 | 5 | promise1.catch((error) => { 6 | console.error(error); 7 | }); 8 | // expected output: Uh-oh! 9 | -------------------------------------------------------------------------------- /regexp/regexp-prototype-flags.js: -------------------------------------------------------------------------------- 1 | // outputs RegExp flags in alphabetical order 2 | 3 | console.log(/foo/ig.flags); 4 | // expected output: "gi" 5 | 6 | console.log(/bar/myu.flags); 7 | // expected output: "muy" 8 | -------------------------------------------------------------------------------- /sharedarraybuffer/sharedarraybuffer-bytelength.js: -------------------------------------------------------------------------------- 1 | // create a SharedArrayBuffer with a size in bytes 2 | const buffer = new SharedArrayBuffer(8); 3 | 4 | console.log(buffer.byteLength); 5 | // expected output: 8 6 | -------------------------------------------------------------------------------- /sharedarraybuffer/sharedarraybuffer-constructor.js: -------------------------------------------------------------------------------- 1 | // create a SharedArrayBuffer with a size in bytes 2 | const buffer = new SharedArrayBuffer(8); 3 | 4 | console.log(buffer.byteLength); 5 | // expected output: 8 6 | -------------------------------------------------------------------------------- /string/string-tostring.js: -------------------------------------------------------------------------------- 1 | const stringObj = new String('foo'); 2 | 3 | console.log(stringObj); 4 | // expected output: String { "foo" } 5 | 6 | console.log(stringObj.toString()); 7 | // expected output: "foo" 8 | -------------------------------------------------------------------------------- /string/string-valueof.js: -------------------------------------------------------------------------------- 1 | const stringObj = new String('foo'); 2 | 3 | console.log(stringObj); 4 | // expected output: String { "foo" } 5 | 6 | console.log(stringObj.valueOf()); 7 | // expected output: "foo" 8 | -------------------------------------------------------------------------------- /ALGO/number_game.py: -------------------------------------------------------------------------------- 1 | def number_game(x,y): 2 | if x > y: 3 | return [n for n in range(y,x) if n%2==0] 4 | elif y==x: 5 | return [] 6 | else: 7 | return [n for n in range(x,y) if n%2!=0] 8 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-tostring.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | 3 | const uint8String = uint8.toString(); 4 | 5 | console.log(uint8String.startsWith('10')); 6 | // expected output: true 7 | -------------------------------------------------------------------------------- /SANDBOX/leet_code_64.js: -------------------------------------------------------------------------------- 1 | // Work through this problem on https://leetcode.com/problems/minimum-path-sum/ 2 | // and use the specs given there. Feel free to use this file for scratch work. 3 | 4 | function minPathSum(grid) {} 5 | -------------------------------------------------------------------------------- /SANDBOX/leet_code_70.js: -------------------------------------------------------------------------------- 1 | // Work through this problem on https://leetcode.com/problems/climbing-stairs/ 2 | // and use the specs given there. Feel free to use this file for scratch work. 3 | 4 | function climbStairs(n) {} 5 | -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/findMin.js: -------------------------------------------------------------------------------- 1 | function findMin(root) { 2 | if (!root) return null; 3 | 4 | while (root.left) root = root.left; 5 | return root; 6 | } 7 | 8 | module.exports = { 9 | findMin, 10 | }; 11 | -------------------------------------------------------------------------------- /Trees/Binary-Search-Tree/getHeight.js: -------------------------------------------------------------------------------- 1 | function getHeight(root) { 2 | if (!root) return -1; 3 | return 1 + Math.max(getHeight(root.left), getHeight(root.right)); 4 | } 5 | 6 | module.exports = { 7 | getHeight, 8 | }; 9 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/first-io-count-newlines.js: -------------------------------------------------------------------------------- 1 | git const fs = require( 'fs' ); 2 | 3 | const file = fs.readFileSync( process.argv[ 2 ] ).toString(); 4 | 5 | console.log( file.split( '\n' ).length - 1 ); 6 | -------------------------------------------------------------------------------- /array/array-every.js: -------------------------------------------------------------------------------- 1 | const isBelowThreshold = (currentValue) => currentValue < 40; 2 | 3 | const array1 = [1, 30, 39, 29, 10, 13]; 4 | 5 | console.log(array1.every(isBelowThreshold)); 6 | // expected output: true 7 | -------------------------------------------------------------------------------- /array/array-some.js: -------------------------------------------------------------------------------- 1 | const array = [1, 2, 3, 4, 5]; 2 | 3 | // checks whether an element is even 4 | const even = (element) => element % 2 === 0; 5 | 6 | console.log(array.some(even)); 7 | // expected output: true 8 | -------------------------------------------------------------------------------- /date/date-tostring.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | console.log(event.toString()); 4 | // expected output: Tue Aug 19 1975 23:15:30 GMT+0200 (CEST) 5 | // (note: your timezone may vary) 6 | -------------------------------------------------------------------------------- /editable-samples/repl/array-slice/array-slice.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var init = 'var a = ["zero", "one", "two", "three"];'; 4 | 5 | inputBox.value = init; 6 | var event = new Event('change'); 7 | inputBox.dispatchEvent(event); 8 | -------------------------------------------------------------------------------- /expressions/expressions-commaoperators.js: -------------------------------------------------------------------------------- 1 | let x = 1; 2 | 3 | x = (x++, x); 4 | 5 | console.log(x); 6 | // expected output: 2 7 | 8 | x = (2, 3); 9 | 10 | console.log(x); 11 | // expected output: 3 12 | -------------------------------------------------------------------------------- /expressions/expressions-logical-and-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 1; 2 | let b = 0; 3 | 4 | a &&= 2; 5 | console.log(a); 6 | // expected output: 2 7 | 8 | b &&= 2; 9 | console.log(b); 10 | // expected output: 0 11 | -------------------------------------------------------------------------------- /map/map-prototype-has.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | map1.set('bar', 'foo'); 3 | 4 | console.log(map1.has('bar')); 5 | // expected output: true 6 | 7 | console.log(map1.has('baz')); 8 | // expected output: false 9 | -------------------------------------------------------------------------------- /statement/statement-dowhile.js: -------------------------------------------------------------------------------- 1 | let result = ''; 2 | let i = 0; 3 | 4 | do { 5 | i = i + 1; 6 | result = result + i; 7 | } while (i < 5); 8 | 9 | console.log(result); 10 | // expected result: "12345" 11 | -------------------------------------------------------------------------------- /string/string-trim.js: -------------------------------------------------------------------------------- 1 | const greeting = ' Hello world! '; 2 | 3 | console.log(greeting); 4 | // expected output: " Hello world! "; 5 | 6 | console.log(greeting.trim()); 7 | // expected output: "Hello world!"; 8 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-hasinstance.js: -------------------------------------------------------------------------------- 1 | class Array1 { 2 | static [Symbol.hasInstance](instance) { 3 | return Array.isArray(instance); 4 | } 5 | } 6 | 7 | console.log([] instanceof Array1); 8 | // expected output: true 9 | -------------------------------------------------------------------------------- /Utilities-Snippets/general/arrEq.js: -------------------------------------------------------------------------------- 1 | const equals = (a, b) => { 2 | if (a.length !== b.length) return false; 3 | for (let i = 0; i < a.length; i++) { 4 | if (a[i] !== b[i]) return false; 5 | } 6 | return true; 7 | }; 8 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/count-newlines.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | 3 | const file = fs.readFileSync(process.argv[0]); 4 | 5 | const arr = file.toString(); 6 | 7 | console.log(arr.split("\n").length - 1); 8 | -------------------------------------------------------------------------------- /array/array-concat.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | const array2 = ['d', 'e', 'f']; 3 | const array3 = array1.concat(array2); 4 | 5 | console.log(array3); 6 | // expected output: Array ["a", "b", "c", "d", "e", "f"] 7 | -------------------------------------------------------------------------------- /date/date-gettime.js: -------------------------------------------------------------------------------- 1 | const moonLanding = new Date('July 20, 69 00:20:18 GMT+00:00'); 2 | 3 | // milliseconds since Jan 1, 1970, 00:00:00.000 GMT 4 | console.log(moonLanding.getTime()); 5 | // expected output: -14254782000 6 | -------------------------------------------------------------------------------- /json/json-parse.js: -------------------------------------------------------------------------------- 1 | const json = '{"result":true, "count":42}'; 2 | const obj = JSON.parse(json); 3 | 4 | console.log(obj.count); 5 | // expected output: 42 6 | 7 | console.log(obj.result); 8 | // expected output: true 9 | -------------------------------------------------------------------------------- /map/map-prototype-get.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | map1.set('bar', 'foo'); 3 | 4 | console.log(map1.get('bar')); 5 | // expected output: "foo" 6 | 7 | console.log(map1.get('baz')); 8 | // expected output: undefined 9 | -------------------------------------------------------------------------------- /map/map-prototype-set.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | map1.set('bar', 'foo'); 3 | 4 | console.log(map1.get('bar')); 5 | // expected output: "foo" 6 | 7 | console.log(map1.get('baz')); 8 | // expected output: undefined 9 | -------------------------------------------------------------------------------- /number/number-epsilon.js: -------------------------------------------------------------------------------- 1 | const result = Math.abs(0.2 - 0.3 + 0.1); 2 | 3 | console.log(result); 4 | // expected output: 2.7755575615628914e-17 5 | 6 | console.log(result < Number.EPSILON); 7 | // expected output: true 8 | -------------------------------------------------------------------------------- /string/string-startswith.js: -------------------------------------------------------------------------------- 1 | const str1 = 'Saturday night plans'; 2 | 3 | console.log(str1.startsWith('Sat')); 4 | // expected output: true 5 | 6 | console.log(str1.startsWith('Sat', 3)); 7 | // expected output: false 8 | -------------------------------------------------------------------------------- /ALGO/money-format/Readme.md: -------------------------------------------------------------------------------- 1 | # Money Formatting 2 | 3 | Given an amount of money as a float, format it as a string. 4 | 5 | ```javascript 6 | formatMoney(2310000.159897); // '2 310 000.16' 7 | formatMoney(1600); // '1 600.00' 8 | ``` 9 | -------------------------------------------------------------------------------- /ALGO/multiplesoffiveandthree.js: -------------------------------------------------------------------------------- 1 | function solution(number){ 2 | var sum = 0; 3 | for(var i=1;i { 2 | if (bigSet.size < smallSet.size) return false; 3 | for (const item of smallSet) { 4 | if (!bigSet.has(item)) return false; 5 | } 6 | return true; 7 | }; 8 | -------------------------------------------------------------------------------- /SANDBOX/04-leet-code-110.js: -------------------------------------------------------------------------------- 1 | // View the full problem and run the test cases at: 2 | // https://leetcode.com/problems/balanced-binary-tree/ 3 | 4 | // Hint: it may be helpful to get the height of your BST 5 | 6 | function isBalanced(root) {} 7 | -------------------------------------------------------------------------------- /SANDBOX/nim-game.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/nim-game/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number} n 6 | * @return {boolean} 7 | */ 8 | var canWinNim = function (n) { 9 | return n % 4; 10 | }; 11 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/01-reverse-a-string.js: -------------------------------------------------------------------------------- 1 | function reverseString(str) { 2 | strarray = str.split(""); 3 | strarray.reverse(); 4 | return strarray.join(""); 5 | } 6 | 7 | console.log(reverseString("hello")); 8 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/13-falsy-bouncer.js: -------------------------------------------------------------------------------- 1 | function bouncer(arr) { 2 | // Don't show a false ID to this bouncer. 3 | 4 | return arr.filter(Boolean); 5 | } 6 | 7 | console.log(bouncer([7, "ate", "", false, 9])); 8 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/first-async-count-newlines.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | 3 | fs.readFile(process.argv[2], (err, data) => { 4 | if (err) throw err; 5 | console.log(data.toString().split("\n").length - 1); 6 | }); 7 | -------------------------------------------------------------------------------- /array/array-lastindexof.js: -------------------------------------------------------------------------------- 1 | const animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo']; 2 | 3 | console.log(animals.lastIndexOf('Dodo')); 4 | // expected output: 3 5 | 6 | console.log(animals.lastIndexOf('Tiger')); 7 | // expected output: 1 8 | -------------------------------------------------------------------------------- /array/array-shift.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 2, 3]; 2 | 3 | const firstElement = array1.shift(); 4 | 5 | console.log(array1); 6 | // expected output: Array [2, 3] 7 | 8 | console.log(firstElement); 9 | // expected output: 1 10 | -------------------------------------------------------------------------------- /boolean/boolean-valueof.js: -------------------------------------------------------------------------------- 1 | const x = new Boolean(); 2 | 3 | console.log(x.valueOf()); 4 | // expected output: false 5 | 6 | const y = new Boolean('Mozilla'); 7 | 8 | console.log(y.valueOf()); 9 | // expected output: true 10 | -------------------------------------------------------------------------------- /promise/promise-then.js: -------------------------------------------------------------------------------- 1 | const promise1 = new Promise((resolve, reject) => { 2 | resolve('Success!'); 3 | }); 4 | 5 | promise1.then((value) => { 6 | console.log(value); 7 | // expected output: "Success!" 8 | }); 9 | 10 | -------------------------------------------------------------------------------- /statement/statement-block.js: -------------------------------------------------------------------------------- 1 | var x = 1; 2 | let y = 1; 3 | 4 | if (true) { 5 | var x = 2; 6 | let y = 2; 7 | } 8 | 9 | console.log(x); 10 | // expected output: 2 11 | 12 | console.log(y); 13 | // expected output: 1 14 | -------------------------------------------------------------------------------- /statement/statement-forof.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | 3 | for (const element of array1) { 4 | console.log(element); 5 | } 6 | 7 | // expected output: "a" 8 | // expected output: "b" 9 | // expected output: "c" 10 | -------------------------------------------------------------------------------- /string/string-tolocaleuppercase.js: -------------------------------------------------------------------------------- 1 | const city = 'istanbul'; 2 | 3 | console.log(city.toLocaleUpperCase('en-US')); 4 | // expected output: "ISTANBUL" 5 | 6 | console.log(city.toLocaleUpperCase('TR')); 7 | // expected output: "İSTANBUL" 8 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-buffer.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(8); 3 | const uint16 = new Uint16Array(buffer); 4 | 5 | console.log(uint16.buffer.byteLength); 6 | // expected output: 8 7 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-entries.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | const eArr = uint8.entries(); 3 | 4 | eArr.next(); 5 | eArr.next(); 6 | 7 | console.log(eArr.next().value); 8 | // expected output: Array [2, 30] 9 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-values.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([ 10, 20, 30, 40, 50]); 2 | const array1 = uint8.values(); 3 | 4 | array1.next(); 5 | array1.next(); 6 | 7 | console.log(array1.next().value); 8 | // expected output: 30 9 | -------------------------------------------------------------------------------- /MINI-DS-PROJECtS/depth_breadth_first_project/lib/tree_sum.js: -------------------------------------------------------------------------------- 1 | function treeSum(root) { 2 | if (!root) return 0; 3 | 4 | return root.val + treeSum(root.left) + treeSum(root.right); 5 | } 6 | 7 | module.exports = { 8 | treeSum, 9 | }; 10 | -------------------------------------------------------------------------------- /MINI-DS-PROJECtS/tree_order_project/lib/tree_node.js: -------------------------------------------------------------------------------- 1 | class TreeNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.left = null; 5 | this.right = null; 6 | } 7 | } 8 | 9 | module.exports = { 10 | TreeNode, 11 | }; 12 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/08-repeat-a-string.js: -------------------------------------------------------------------------------- 1 | function repeatStringNumTimes(str, num) { 2 | if (num <= 0) { 3 | return ""; 4 | } else return str.repeat(num); 5 | } 6 | 7 | console.log(repeatStringNumTimes("abc", 3)); 8 | -------------------------------------------------------------------------------- /bigint/bigint-tostring.js: -------------------------------------------------------------------------------- 1 | console.log(1024n.toString()); 2 | // expected output: "1024" 3 | 4 | console.log(1024n.toString(2)); 5 | // expected output: "10000000000" 6 | 7 | console.log(1024n.toString(16)); 8 | // expected output: "400" 9 | -------------------------------------------------------------------------------- /classes/classes-constructor.js: -------------------------------------------------------------------------------- 1 | class Polygon { 2 | constructor() { 3 | this.name = 'Polygon'; 4 | } 5 | } 6 | 7 | const poly1 = new Polygon(); 8 | 9 | console.log(poly1.name); 10 | // expected output: "Polygon" 11 | -------------------------------------------------------------------------------- /expressions/expressions-addition-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 2; 2 | let b = 'hello'; 3 | 4 | console.log(a += 3); // addition 5 | // expected output: 5 6 | 7 | console.log(b += ' world'); // concatenation 8 | // expected output: "hello world" 9 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-and-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 5; // 00000000000000000000000000000101 2 | a &= 3; // 00000000000000000000000000000011 3 | 4 | console.log(a); // 00000000000000000000000000000001 5 | // expected output: 1 6 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-or-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 5; // 00000000000000000000000000000101 2 | a |= 3; // 00000000000000000000000000000011 3 | 4 | console.log(a); // 00000000000000000000000000000111 5 | // expected output: 7 6 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-or.js: -------------------------------------------------------------------------------- 1 | const a = 5; // 00000000000000000000000000000101 2 | const b = 3; // 00000000000000000000000000000011 3 | 4 | console.log(a | b); // 00000000000000000000000000000111 5 | // expected output: 7 6 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-xor-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 5; // 00000000000000000000000000000101 2 | a ^= 3; // 00000000000000000000000000000011 3 | 4 | console.log(a); // 00000000000000000000000000000110 5 | // expected output: 6 6 | -------------------------------------------------------------------------------- /statement/statement-continue.js: -------------------------------------------------------------------------------- 1 | let text = ''; 2 | 3 | for (let i = 0; i < 10; i++) { 4 | if (i === 3) { 5 | continue; 6 | } 7 | text = text + i; 8 | } 9 | 10 | console.log(text); 11 | // expected output: "012456789" 12 | -------------------------------------------------------------------------------- /string/string-concat.js: -------------------------------------------------------------------------------- 1 | const str1 = 'Hello'; 2 | const str2 = 'World'; 3 | 4 | console.log(str1.concat(' ', str2)); 5 | // expected output: "Hello World" 6 | 7 | console.log(str2.concat(', ', str1)); 8 | // expected output: "World, Hello" 9 | -------------------------------------------------------------------------------- /string/string-match.js: -------------------------------------------------------------------------------- 1 | const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.'; 2 | const regex = /[A-Z]/g; 3 | const found = paragraph.match(regex); 4 | 5 | console.log(found); 6 | // expected output: Array ["T", "I"] 7 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-lastindexof.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 50, 50, 50, 60]); 2 | 3 | console.log(uint8.lastIndexOf(50, 5)); 4 | // expected output: 4 5 | 6 | console.log(uint8.lastIndexOf(50, 3)); 7 | // expected output: 3 8 | -------------------------------------------------------------------------------- /Arrays/array-helpers/flatten-arrays.js: -------------------------------------------------------------------------------- 1 | /*Simple Function to flatten an array into a single layer */ 2 | const flatten = (array) => 3 | array.reduce((accum, ele) => { 4 | return accum.concat(Array.isArray(ele) ? flatten(ele) : ele); 5 | }, []); 6 | -------------------------------------------------------------------------------- /General-Interview-Prep/geeksforgeeks/README.md: -------------------------------------------------------------------------------- 1 | # Geeksforgeeks Problems 2 | 3 | - [Analysis of algorithm](https://github.com/bgoonz/DATA-STRUCTURES-ALGOS-CODEBASE/blob/master/General-Interview-Prep/geeksforgeeks/introduction/01-analysis-of-algorithm.js) 4 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/intermediate-algorithm/15-finders-keepers.js: -------------------------------------------------------------------------------- 1 | function findElement(arr, func) { 2 | const num = arr.filter(func); 3 | return num[0]; 4 | } 5 | 6 | console.log(findElement([1, 3, 5, 8, 9, 10], (num) => num % 2 === 0)); 7 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-and.js: -------------------------------------------------------------------------------- 1 | const a = 5; // 00000000000000000000000000000101 2 | const b = 3; // 00000000000000000000000000000011 3 | 4 | console.log(a & b); // 00000000000000000000000000000001 5 | // expected output: 1 6 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-xor.js: -------------------------------------------------------------------------------- 1 | const a = 5; // 00000000000000000000000000000101 2 | const b = 3; // 00000000000000000000000000000011 3 | 4 | console.log(a ^ b); // 00000000000000000000000000000110 5 | // expected output: 6 6 | -------------------------------------------------------------------------------- /expressions/expressions-left-shift.js: -------------------------------------------------------------------------------- 1 | const a = 5; // 00000000000000000000000000000101 2 | const b = 2; // 00000000000000000000000000000010 3 | 4 | console.log(a << b); // 00000000000000000000000000010100 5 | // expected output: 20 6 | -------------------------------------------------------------------------------- /functions/functions-arrow.js: -------------------------------------------------------------------------------- 1 | const materials = [ 2 | 'Hydrogen', 3 | 'Helium', 4 | 'Lithium', 5 | 'Beryllium' 6 | ]; 7 | 8 | console.log(materials.map(material => material.length)); 9 | // expected output: Array [8, 6, 7, 9] 10 | -------------------------------------------------------------------------------- /number/number-isfinite.js: -------------------------------------------------------------------------------- 1 | console.log(Number.isFinite(1 / 0)); 2 | // expected output: false 3 | 4 | console.log(Number.isFinite(10 / 5)); 5 | // expected output: true 6 | 7 | console.log(Number.isFinite(0 / 0)); 8 | // expected output: false 9 | -------------------------------------------------------------------------------- /object/object-fromentries.js: -------------------------------------------------------------------------------- 1 | const entries = new Map([ 2 | ['foo', 'bar'], 3 | ['baz', 42] 4 | ]); 5 | 6 | const obj = Object.fromEntries(entries); 7 | 8 | console.log(obj); 9 | // expected output: Object { foo: "bar", baz: 42 } 10 | -------------------------------------------------------------------------------- /set/set-prototype-clear.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | set1.add(1); 3 | set1.add('foo'); 4 | 5 | console.log(set1.size); 6 | // expected output: 2 7 | 8 | set1.clear(); 9 | 10 | console.log(set1.size); 11 | // expected output: 0 12 | -------------------------------------------------------------------------------- /set/set-prototype-size.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | const object1 = {}; 3 | 4 | set1.add(42); 5 | set1.add('forty two'); 6 | set1.add('forty two'); 7 | set1.add(object1); 8 | 9 | console.log(set1.size); 10 | // expected output: 3 11 | -------------------------------------------------------------------------------- /statement/statement-empty.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 2, 3]; 2 | 3 | // Assign all array values to 0 4 | for (let i = 0; i < array1.length; array1[i++] = 0) /* empty statement */; 5 | 6 | console.log(array1); 7 | // expected output: Array [0, 0, 0] 8 | -------------------------------------------------------------------------------- /ALGO/__PYTHON/fib_series.py: -------------------------------------------------------------------------------- 1 | def fib_series(count): 2 | a=0 3 | b=1 4 | c=1 5 | for i in range(count): 6 | a=b 7 | b=c 8 | c=a+b 9 | print(a) 10 | 11 | fib_series(10) 12 | 13 | 14 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-iterator.js: -------------------------------------------------------------------------------- 1 | const iterable1 = {}; 2 | 3 | iterable1[Symbol.iterator] = function* () { 4 | yield 1; 5 | yield 2; 6 | yield 3; 7 | }; 8 | 9 | console.log([...iterable1]); 10 | // expected output: Array [1, 2, 3] 11 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-every.js: -------------------------------------------------------------------------------- 1 | function isNegative(element, index, array) { 2 | return element < 0; 3 | } 4 | 5 | const int8 = new Int8Array([-10, -20, -30, -40, -50]); 6 | 7 | console.log(int8.every(isNegative)); 8 | // expected output: true 9 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-reduce.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([0, 1, 2, 3]); 2 | 3 | function sum(previousValue, currentValue) { 4 | return previousValue + currentValue; 5 | } 6 | 7 | console.log(uint8.reduce(sum)); 8 | // expected output: 6 9 | -------------------------------------------------------------------------------- /Complete-Projects/18_depth_breadth_first_project/lib/tree_height.js: -------------------------------------------------------------------------------- 1 | function treeHeight(root) { 2 | if (!root) return -1; 3 | return Math.max(treeHeight(root.left), treeHeight(root.right)) + 1; 4 | } 5 | 6 | module.exports = { 7 | treeHeight, 8 | }; 9 | -------------------------------------------------------------------------------- /MINI-DS-PROJECtS/depth_breadth_first_project/lib/tree_node.js: -------------------------------------------------------------------------------- 1 | class TreeNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.left = null; 5 | this.right = null; 6 | } 7 | } 8 | 9 | module.exports = { 10 | TreeNode, 11 | }; 12 | -------------------------------------------------------------------------------- /Recursion/fibonacci-versions/memo-fibonacci.js: -------------------------------------------------------------------------------- 1 | function fib( 2 | n, 3 | memo = { 4 | 0: 1, 5 | 1: 1, 6 | } 7 | ) { 8 | if (n in memo) return memo[n]; 9 | memo[n] = fib(n - 1, memo) + fib(n - 2, memo); 10 | return memo[n]; 11 | } 12 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/02-factorialize.js: -------------------------------------------------------------------------------- 1 | function factorialize(num) { 2 | if (num === 0) { 3 | return 1; 4 | } else { 5 | return num * factorialize(num - 1); 6 | } 7 | } 8 | 9 | console.log(factorialize(5)); 10 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/15-where-do-i-belong.js: -------------------------------------------------------------------------------- 1 | function getIndexToIns(arr, num) { 2 | arr.push(num); 3 | arr.sort((a, b) => a - b); 4 | return arr.indexOf(num); 5 | } 6 | 7 | console.log(getIndexToIns([10, 20, 30, 40, 50], 35)); 8 | -------------------------------------------------------------------------------- /set/set-prototype-add.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | 3 | set1.add(42); 4 | set1.add(42); 5 | set1.add(13); 6 | 7 | for (const item of set1) { 8 | console.log(item); 9 | // expected output: 42 10 | // expected output: 13 11 | } 12 | -------------------------------------------------------------------------------- /statement/statement-label.js: -------------------------------------------------------------------------------- 1 | let str = ''; 2 | 3 | loop1: 4 | for (let i = 0; i < 5; i++) { 5 | if (i === 1) { 6 | continue loop1; 7 | } 8 | str = str + i; 9 | } 10 | 11 | console.log(str); 12 | // expected output: "0234" 13 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/string-format.js: -------------------------------------------------------------------------------- 1 | export default function (string /* , args */) { 2 | const args = Array.prototype.slice.call(arguments, 1); 3 | 4 | return string.replace(/\{(\d+)\}/g, (_, arg) => { 5 | return arg in args ? args[arg] : _; 6 | }); 7 | } 8 | -------------------------------------------------------------------------------- /ALGO/__PYTHON/exists_in.py: -------------------------------------------------------------------------------- 1 | def find(arr,search,n): 2 | for i in range(n): 3 | if arr[i]== search: 4 | return True 5 | break 6 | 7 | arr=[1,2,3,4,5,6] 8 | search=4 9 | 10 | print(find(arr,search,6)) 11 | 12 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-tostringtag.js: -------------------------------------------------------------------------------- 1 | class ValidatorClass { 2 | get [Symbol.toStringTag]() { 3 | return 'Validator'; 4 | } 5 | } 6 | 7 | console.log(Object.prototype.toString.call(new ValidatorClass())); 8 | // expected output: "[object Validator]" 9 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-find.js: -------------------------------------------------------------------------------- 1 | function isNegative(element, index, array) { 2 | return element < 0; 3 | } 4 | 5 | const int8 = new Int8Array([10, 0, -10, 20, -30, 40, -50]); 6 | 7 | console.log(int8.find(isNegative)); 8 | // expected output: -10 9 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-findindex.js: -------------------------------------------------------------------------------- 1 | function isNegative(element, index, array) { 2 | return element < 0; 3 | } 4 | 5 | const int8 = new Int8Array([10, -20, 30, -40, 50]); 6 | 7 | console.log(int8.findIndex(isNegative)); 8 | // expected output: 1 9 | -------------------------------------------------------------------------------- /Complete-Projects/18_depth_breadth_first_project/lib/tree_node.js: -------------------------------------------------------------------------------- 1 | class TreeNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.left = null; 5 | this.right = null; 6 | } 7 | } 8 | 9 | module.exports = { 10 | TreeNode, 11 | }; 12 | -------------------------------------------------------------------------------- /Recursion/lucas-num-versions/memo-lucasnum.js: -------------------------------------------------------------------------------- 1 | function lucas( 2 | n, 3 | memo = { 4 | 0: 2, 5 | 1: 1, 6 | } 7 | ) { 8 | if (n in memo) return memo[n]; 9 | memo[n] = lucas(n - 1, memo) + lucas(n - 2, memo); 10 | return memo[n]; 11 | } 12 | -------------------------------------------------------------------------------- /Strings/python/reverse-word/rev-word.py: -------------------------------------------------------------------------------- 1 | def rev_word(inStr:str)->str: 2 | return ' '.join(inStr.split()[::-1]) 3 | 4 | print(rev_word("Python is kinda cool")) 5 | 6 | # Print Output: 7 | # cool kinda is Python 8 | # Variables: 9 | # {} 10 | -------------------------------------------------------------------------------- /array/array-keys.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | const iterator = array1.keys(); 3 | 4 | for (const key of iterator) { 5 | console.log(key); 6 | } 7 | 8 | // expected output: 0 9 | // expected output: 1 10 | // expected output: 2 11 | -------------------------------------------------------------------------------- /array/array-reduce-right.js: -------------------------------------------------------------------------------- 1 | const array1 = [ 2 | [0, 1], 3 | [2, 3], 4 | [4, 5], 5 | ].reduceRight((accumulator, currentValue) => accumulator.concat(currentValue)); 6 | 7 | console.log(array1); 8 | // expected output: Array [4, 5, 2, 3, 0, 1] 9 | -------------------------------------------------------------------------------- /boolean/boolean-tostring.js: -------------------------------------------------------------------------------- 1 | const flag1 = new Boolean(true); 2 | 3 | console.log(flag1.toString()); 4 | // expected output: "true" 5 | 6 | const flag2 = new Boolean(1); 7 | 8 | console.log(flag2.toString()); 9 | // expected output: "true" 10 | -------------------------------------------------------------------------------- /expressions/expressions-division-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 3; 2 | 3 | console.log(a /= 2); 4 | // expected output: 1.5 5 | 6 | console.log(a /= 0); 7 | // expected output: Infinity 8 | 9 | console.log(a /= 'hello'); 10 | // expected output: NaN 11 | -------------------------------------------------------------------------------- /expressions/expressions-exponentiation-assignment.js: -------------------------------------------------------------------------------- 1 | let a = 3; 2 | 3 | console.log(a **= 2); 4 | // expected output: 9 5 | 6 | console.log(a **= 0); 7 | // expected output: 1 8 | 9 | console.log(a **= 'hello'); 10 | // expected output: NaN 11 | -------------------------------------------------------------------------------- /globalprops/globalprops-null.js: -------------------------------------------------------------------------------- 1 | function getVowels(str) { 2 | const m = str.match(/[aeiou]/gi); 3 | if (m === null) { 4 | return 0; 5 | } 6 | return m.length; 7 | } 8 | 9 | console.log(getVowels('sky')); 10 | // expected output: 0 11 | -------------------------------------------------------------------------------- /globalprops/globalprops-undefined.js: -------------------------------------------------------------------------------- 1 | function test(t) { 2 | if (t === undefined) { 3 | return 'Undefined value!'; 4 | } 5 | return t; 6 | } 7 | 8 | let x; 9 | 10 | console.log(test(x)); 11 | // expected output: "Undefined value!" 12 | -------------------------------------------------------------------------------- /statement/statement-forin.js: -------------------------------------------------------------------------------- 1 | const object = { a: 1, b: 2, c: 3 }; 2 | 3 | for (const property in object) { 4 | console.log(`${property}: ${object[property]}`); 5 | } 6 | 7 | // expected output: 8 | // "a: 1" 9 | // "b: 2" 10 | // "c: 3" 11 | -------------------------------------------------------------------------------- /string/string-charat.js: -------------------------------------------------------------------------------- 1 | const sentence = 'The quick brown fox jumps over the lazy dog.'; 2 | 3 | const index = 4; 4 | 5 | console.log(`The character at index ${index} is ${sentence.charAt(index)}`); 6 | // expected output: "The character at index 4 is q" 7 | -------------------------------------------------------------------------------- /ALGO/fibonacci/fibonacci-memo.js: -------------------------------------------------------------------------------- 1 | const fibonacci = ( 2 | n, 3 | memo = { 4 | 0: 0, 5 | 1: 1, 6 | } 7 | ) => { 8 | if (n in memo) return memo[n]; 9 | memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo); 10 | return memo[n]; 11 | }; 12 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-matchall.js: -------------------------------------------------------------------------------- 1 | const re = /[0-9]+/g; 2 | const str = '2016-01-02|2019-03-07'; 3 | const result = re[Symbol.matchAll](str); 4 | 5 | console.log(Array.from(result, x => x[0])); 6 | // expected output: Array ["2016", "01", "02", "2019", "03", "07"] 7 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-toprimitive.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | [Symbol.toPrimitive](hint) { 3 | if (hint === 'number') { 4 | return 42; 5 | } 6 | return null; 7 | } 8 | }; 9 | 10 | console.log(+object1); 11 | // expected output: 42 12 | -------------------------------------------------------------------------------- /File-System/file-name-from-path/nameFromPath.js: -------------------------------------------------------------------------------- 1 | const nameFPath = function (path) { 2 | const name = path.split("/").pop(); 3 | return name; 4 | }; 5 | const p = "DS-n-AlgosListssimple-singly-linked-list.js"; 6 | 7 | console.log("nameFPath(p): ", nameFPath(p)); 8 | -------------------------------------------------------------------------------- /array/array-flat.js: -------------------------------------------------------------------------------- 1 | const arr1 = [0, 1, 2, [3, 4]]; 2 | 3 | console.log(arr1.flat()); 4 | // expected output: [0, 1, 2, 3, 4] 5 | 6 | const arr2 = [0, 1, 2, [[[3, 4]]]]; 7 | 8 | console.log(arr2.flat(2)); 9 | // expected output: [0, 1, 2, [3, 4]] 10 | -------------------------------------------------------------------------------- /arraybuffer/arraybuffer-bytelength.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(8); 3 | 4 | // use byteLength to check the size 5 | const bytes = buffer.byteLength; 6 | 7 | console.log(bytes); 8 | // expected output: 8 9 | -------------------------------------------------------------------------------- /expressions/expressions-bitwise-not.js: -------------------------------------------------------------------------------- 1 | const a = 5; // 0000000000000101 2 | const b = -3; // 1111111111111101 3 | 4 | console.log(~a); // 1111111111111010 5 | // expected output: -6 6 | 7 | console.log(~b); // 0000000000000010 8 | // expected output: 2 9 | -------------------------------------------------------------------------------- /regexp/regexp-prototype-dotall.js: -------------------------------------------------------------------------------- 1 | const regex1 = new RegExp('foo', 's'); 2 | 3 | console.log(regex1.dotAll); 4 | // expected output: true 5 | 6 | const regex2 = new RegExp('bar'); 7 | 8 | console.log(regex2.dotAll); 9 | // expected output: false 10 | -------------------------------------------------------------------------------- /statement/statement-trycatch.js: -------------------------------------------------------------------------------- 1 | try { 2 | nonExistentFunction(); 3 | } catch (error) { 4 | console.error(error); 5 | // expected output: ReferenceError: nonExistentFunction is not defined 6 | // Note - error messages will vary depending on browser 7 | } 8 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/Recursion-countdown.js: -------------------------------------------------------------------------------- 1 | function countdown(n) { 2 | if (n < 1) { 3 | return []; 4 | } else { 5 | const countArray = countdown(n - 1); 6 | countArray.unshift(n); 7 | return countArray; 8 | } 9 | } 10 | console.log(countdown(5)); 11 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-includes.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | 3 | console.log(uint8.includes(20)); 4 | // expected output: true 5 | 6 | // check from position 3 7 | console.log(uint8.includes(20, 3)); 8 | // expected output: false 9 | -------------------------------------------------------------------------------- /File-System/file-utilities/file-name-from-path.js: -------------------------------------------------------------------------------- 1 | const nameFPath = function (path) { 2 | const name = path.split("/").pop(); 3 | return name; 4 | }; 5 | const p = "DS-n-Algos/Lists/simple-singly-linked-list.js"; 6 | 7 | console.log("nameFPath(p): ", nameFPath(p)); 8 | -------------------------------------------------------------------------------- /General-Interview-Prep/freecodecamp/basic/18-boo-hoo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Bryan Guner 3 | * Copyright © 2018 ashish.me 4 | * bryan.guner@gmail.com 5 | */ 6 | 7 | function booWho(bool) { 8 | return typeof bool === "boolean"; 9 | } 10 | 11 | booWho(null); 12 | -------------------------------------------------------------------------------- /date/date-setutcdate.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30 GMT-3:00'); 2 | 3 | console.log(event.getUTCDate()); 4 | // expected output: 20 5 | 6 | event.setUTCDate(19); 7 | 8 | console.log(event.getUTCDate()); 9 | // expected output: 19 10 | -------------------------------------------------------------------------------- /map/map-prototype-clear.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | 3 | map1.set('bar', 'baz'); 4 | map1.set(1, 'foo'); 5 | 6 | console.log(map1.size); 7 | // expected output: 2 8 | 9 | map1.clear(); 10 | 11 | console.log(map1.size); 12 | // expected output: 0 13 | -------------------------------------------------------------------------------- /math/math-max.js: -------------------------------------------------------------------------------- 1 | console.log(Math.max(1, 3, 2)); 2 | // expected output: 3 3 | 4 | console.log(Math.max(-1, -3, -2)); 5 | // expected output: -1 6 | 7 | const array1 = [1, 3, 2]; 8 | 9 | console.log(Math.max(...array1)); 10 | // expected output: 3 11 | -------------------------------------------------------------------------------- /math/math-min.js: -------------------------------------------------------------------------------- 1 | console.log(Math.min(2, 3, 1)); 2 | // expected output: 1 3 | 4 | console.log(Math.min(-2, -3, -1)); 5 | // expected output: -3 6 | 7 | const array1 = [2, 3, 1]; 8 | 9 | console.log(Math.min(...array1)); 10 | // expected output: 1 11 | -------------------------------------------------------------------------------- /number/number-nan.js: -------------------------------------------------------------------------------- 1 | function clean(x) { 2 | if (x === Number.NaN) { 3 | // can never be true 4 | return null; 5 | } 6 | if (isNaN(x)) { 7 | return 0; 8 | } 9 | } 10 | 11 | console.log(clean(Number.NaN)); 12 | // expected output: 0 13 | -------------------------------------------------------------------------------- /regexp/regexp-prototype-global.js: -------------------------------------------------------------------------------- 1 | const regex1 = new RegExp('foo', 'g'); 2 | 3 | console.log(regex1.global); 4 | // expected output: true 5 | 6 | const regex2 = new RegExp('bar', 'i'); 7 | 8 | console.log(regex2.global); 9 | // expected output: false 10 | -------------------------------------------------------------------------------- /string/string-endswith.js: -------------------------------------------------------------------------------- 1 | const str1 = 'Cats are the best!'; 2 | 3 | console.log(str1.endsWith('best', 17)); 4 | // expected output: true 5 | 6 | const str2 = 'Is this a question'; 7 | 8 | console.log(str2.endsWith('?')); 9 | // expected output: false 10 | -------------------------------------------------------------------------------- /string/string-padend.js: -------------------------------------------------------------------------------- 1 | const str1 = 'Breaded Mushrooms'; 2 | 3 | console.log(str1.padEnd(25, '.')); 4 | // expected output: "Breaded Mushrooms........" 5 | 6 | const str2 = '200'; 7 | 8 | console.log(str2.padEnd(5)); 9 | // expected output: "200 " 10 | -------------------------------------------------------------------------------- /string/string-tolocalelowercase.js: -------------------------------------------------------------------------------- 1 | const dotted = 'İstanbul'; 2 | 3 | console.log(`EN-US: ${dotted.toLocaleLowerCase('en-US')}`); 4 | // expected output: "i̇stanbul" 5 | 6 | console.log(`TR: ${dotted.toLocaleLowerCase('tr')}`); 7 | // expected output: "istanbul" 8 | -------------------------------------------------------------------------------- /ALGO/factorial.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | * Create the function to find the factorial of a given integer 4 | */ 5 | 6 | function factorial(n) { 7 | if (n === 0) { 8 | return 1; 9 | } else { 10 | return n * factorial(n - 1); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-subarray.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | 3 | console.log(uint8.subarray(1, 3)); 4 | // expected output: Uint8Array [20, 30] 5 | 6 | console.log(uint8.subarray(1)); 7 | // expected output: Uint8Array [20, 30, 40, 50] 8 | -------------------------------------------------------------------------------- /POJOs/objPropMap/obj-prop-map.js: -------------------------------------------------------------------------------- 1 | export function mapClone(object, callback) { 2 | const clone = {}; 3 | for (const key in object) { 4 | if (hasOwnProperty(object, key)) { 5 | clone[key] = callback(object[key]); 6 | } 7 | } 8 | return clone; 9 | } 10 | -------------------------------------------------------------------------------- /Recursion/fibonacci-versions/naive-fibonacci.js: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | return n === 1 || n === 2 ? 1 : fib(n - 1) + fib(n - 2); 3 | } 4 | 5 | // let fibonacci = (40) => { 6 | // if (n === 1 || n === 2) return 1; 7 | // return fibonacci(n - 1) + fibonacci(n - 2); 8 | // }; 9 | -------------------------------------------------------------------------------- /SANDBOX/powx-n.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/powx-n/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number} x 6 | * @param {number} n 7 | * @return {number} 8 | */ 9 | 10 | var myPow = function (x, n) { 11 | return Math.pow(x, n); 12 | }; 13 | -------------------------------------------------------------------------------- /Sorting-n-Searching/1-searching-algorithms/depth_breadth_first_project/lib/tree_height.js: -------------------------------------------------------------------------------- 1 | function treeHeight(root) { 2 | if (!root) return -1; 3 | return 1 + Math.max(treeHeight(root.left), treeHeight(root.right)); 4 | } 5 | 6 | module.exports = { 7 | treeHeight, 8 | }; 9 | -------------------------------------------------------------------------------- /_Extra-Practice/30-days-of-code-master/day6_review.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | 3 | for i in range(t): 4 | s = input() 5 | s1 = ''.join([s[i] for i in range(len(s)) if i%2 == 0]) 6 | s2 = ''.join([s[i] for i in range(len(s)) if i%2 != 0]) 7 | print(s1, s2) 8 | -------------------------------------------------------------------------------- /array/array-values.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | const iterator = array1.values(); 3 | 4 | for (const value of iterator) { 5 | console.log(value); 6 | } 7 | 8 | // expected output: "a" 9 | // expected output: "b" 10 | // expected output: "c" 11 | -------------------------------------------------------------------------------- /atomics/atomics-islockfree.js: -------------------------------------------------------------------------------- 1 | console.log(Atomics.isLockFree(3)); 2 | // 3 is not one of the BYTES_PER_ELEMENT values 3 | // expected output: false 4 | 5 | console.log(Atomics.isLockFree(4)); 6 | // 4 is one of the BYTES_PER_ELEMENT values 7 | // expected output: true 8 | -------------------------------------------------------------------------------- /dataview/dataview-byteoffset.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer, 12, 4); //from byte 12 for the next 4 bytes 5 | 6 | console.log(view.byteOffset); 7 | // expected output: 12 8 | -------------------------------------------------------------------------------- /expressions/expressions-assignment.js: -------------------------------------------------------------------------------- 1 | let x = 2; 2 | const y = 3; 3 | 4 | console.log(x); 5 | // expected output: 2 6 | 7 | console.log(x = y + 1); // 3 + 1 8 | // expected output: 4 9 | 10 | console.log(x = x * y); // 4 * 3 11 | // expected output: 12 12 | -------------------------------------------------------------------------------- /expressions/expressions-decrement.js: -------------------------------------------------------------------------------- 1 | let x = 3; 2 | const y = x--; 3 | 4 | console.log(`x:${x}, y:${y}`); 5 | // expected output: "x:2, y:3" 6 | 7 | let a = 3; 8 | const b = --a; 9 | 10 | console.log(`a:${a}, b:${b}`); 11 | // expected output: "a:2, b:2" 12 | -------------------------------------------------------------------------------- /expressions/expressions-increment.js: -------------------------------------------------------------------------------- 1 | let x = 3; 2 | const y = x++; 3 | 4 | console.log(`x:${x}, y:${y}`); 5 | // expected output: "x:4, y:3" 6 | 7 | let a = 3; 8 | const b = ++a; 9 | 10 | console.log(`a:${a}, b:${b}`); 11 | // expected output: "a:4, b:4" 12 | -------------------------------------------------------------------------------- /object/object-isextensible.js: -------------------------------------------------------------------------------- 1 | const object1 = {}; 2 | 3 | console.log(Object.isExtensible(object1)); 4 | // expected output: true 5 | 6 | Object.preventExtensions(object1); 7 | 8 | console.log(Object.isExtensible(object1)); 9 | // expected output: false 10 | -------------------------------------------------------------------------------- /object/object-issealed.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | console.log(Object.isSealed(object1)); 6 | // expected output: false 7 | 8 | Object.seal(object1); 9 | 10 | console.log(Object.isSealed(object1)); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /set/set-prototype-has.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set([1, 2, 3, 4, 5]); 2 | 3 | console.log(set1.has(1)); 4 | // expected output: true 5 | 6 | console.log(set1.has(5)); 7 | // expected output: true 8 | 9 | console.log(set1.has(6)); 10 | // expected output: false 11 | -------------------------------------------------------------------------------- /ALGO/flatten-array/es5.js: -------------------------------------------------------------------------------- 1 | module.exports = function flatten(array) { 2 | return array.reduce((arr, val) => { 3 | // Concat is extremely slow which leads to this being the slowest solution. 4 | return arr.concat(Array.isArray(val) ? flatten(val) : val); 5 | }, []); 6 | }; 7 | -------------------------------------------------------------------------------- /Recursion/fibonacci-versions/tab-fibonacci.js: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | let table = new Array(n + 1); 3 | table[0] = 0; 4 | table[1] = 1; 5 | for (let i = 2; i < table.length; i++) { 6 | table[i] = table[i - 1] + table[i - 2]; 7 | } 8 | return table[n]; 9 | } 10 | -------------------------------------------------------------------------------- /Recursion/lucas-num-versions/tab-lucasnum.js: -------------------------------------------------------------------------------- 1 | function lucas(n) { 2 | let table = new Array(n + 1); 3 | table[0] = 2; 4 | table[1] = 1; 5 | for (let i = 2; i < table.length; i++) { 6 | table[i] = table[i - 1] + table[i - 2]; 7 | } 8 | return table[n]; 9 | } 10 | -------------------------------------------------------------------------------- /SANDBOX/leet_code_105.js: -------------------------------------------------------------------------------- 1 | // View the full problem and run the test cases at: 2 | // https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 3 | 4 | const { TreeNode } = require("./tree_node.js"); 5 | 6 | function buildTree(preorder, inorder) {} 7 | -------------------------------------------------------------------------------- /Sorting-n-Searching/1-searching-algorithms/depth_breadth_first_project/lib/tree_node.js: -------------------------------------------------------------------------------- 1 | class TreeNode { 2 | constructor(val) { 3 | this.val = val; 4 | this.left = null; 5 | this.right = null; 6 | } 7 | } 8 | 9 | module.exports = { 10 | TreeNode, 11 | }; 12 | -------------------------------------------------------------------------------- /_Extra-Practice/30-days-of-code-master/day9_recursion.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if n <= 1: 3 | return 1 4 | else: 5 | return n * factorial(n-1) 6 | 7 | if __name__ == '__main__': 8 | n = factorial(int(input())) 9 | 10 | print(n) 11 | -------------------------------------------------------------------------------- /_Extra-Practice/README.md: -------------------------------------------------------------------------------- 1 | # The data structures 2 | 3 | - [x] Array 4 | - [x] Hash Table 5 | - [x] Set 6 | - [x] Singly Linked List 7 | - [x] Doubly Linked List 8 | - [x] Stack 9 | - [x] Queue 10 | - [x] Tree 11 | - [x] Binary Search Tree 12 | - [x] Trie 13 | - [x] Graph 14 | -------------------------------------------------------------------------------- /date/date-setmilliseconds.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | console.log(event.getMilliseconds()); 4 | // expected output: 0 5 | 6 | event.setMilliseconds(456); 7 | 8 | console.log(event.getMilliseconds()); 9 | // expected output: 456 10 | -------------------------------------------------------------------------------- /expressions/expressions-division.js: -------------------------------------------------------------------------------- 1 | console.log(12 / 2); 2 | // expected output: 6 3 | 4 | console.log(3 / 2); 5 | // expected output: 1.5 6 | 7 | console.log(6 / '3'); 8 | // expected output: 2 9 | 10 | console.log(2 / 0); 11 | // expected output: Infinity 12 | -------------------------------------------------------------------------------- /map/map-prototype-delete.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | map1.set('bar', 'foo'); 3 | 4 | console.log(map1.delete('bar')); 5 | // expected result: true 6 | // (true indicates successful removal) 7 | 8 | console.log(map1.has('bar')); 9 | // expected result: false 10 | -------------------------------------------------------------------------------- /math/math-pi.js: -------------------------------------------------------------------------------- 1 | function calculateCircumference(radius) { 2 | return 2 * Math.PI * radius; 3 | } 4 | 5 | console.log(Math.PI); 6 | // expected output: 3.141592653589793 7 | 8 | console.log(calculateCircumference(10)); 9 | // expected output: 62.83185307179586 10 | -------------------------------------------------------------------------------- /object/object-isfrozen.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | console.log(Object.isFrozen(object1)); 6 | // expected output: false 7 | 8 | Object.freeze(object1); 9 | 10 | console.log(Object.isFrozen(object1)); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /ALGO/__PYTHON/wave.py: -------------------------------------------------------------------------------- 1 | def wave(arr,n): 2 | arr.sort() 3 | for i in range(0,n-1,2): 4 | arr[i],arr[i+1]=arr[i+1],arr[i] 5 | 6 | arr=[10, 90, 49, 2, 1, 5, 23] 7 | 8 | wave(arr,len(arr)) 9 | 10 | for i in range(len(arr)): 11 | print(arr[i],end=" ") 12 | -------------------------------------------------------------------------------- /ALGO/largest-palindrome/Readme.md: -------------------------------------------------------------------------------- 1 | # Largest Palindrome 2 | 3 | Write a function that finds the largest palindrome in a string. All characters can be valid for the palindrome, including whitespace. In the string "I am a red racecar driver" - the largest palindrome would be "d racecar d". 4 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-copywithin.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([ 1, 2, 3, 4, 5, 6, 7, 8 ]); 2 | 3 | // (insert position, start position, end position) 4 | uint8.copyWithin(3, 1, 3); 5 | 6 | console.log(uint8); 7 | // expected output: Uint8Array [1, 2, 3, 2, 3, 6, 7, 8] 8 | -------------------------------------------------------------------------------- /array/array-entries.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | 3 | const iterator1 = array1.entries(); 4 | 5 | console.log(iterator1.next().value); 6 | // expected output: Array [0, "a"] 7 | 8 | console.log(iterator1.next().value); 9 | // expected output: Array [1, "b"] 10 | -------------------------------------------------------------------------------- /dataview/dataview-getfloat32.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setFloat32(1, Math.PI); 6 | 7 | console.log(view.getFloat32(1)); 8 | // expected output: 3.1415927410125732 9 | -------------------------------------------------------------------------------- /dataview/dataview-getfloat64.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setFloat64(1, Math.PI); 6 | 7 | console.log(view.getFloat64(1)); 8 | // expected output: 3.141592653589793 9 | -------------------------------------------------------------------------------- /dataview/dataview-getint8.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setInt8(1, 127); // (max signed 8-bit integer) 6 | 7 | console.log(view.getInt8(1)); 8 | // expected output: 127 9 | -------------------------------------------------------------------------------- /dataview/dataview-setfloat32.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setFloat32(1, Math.PI); 6 | 7 | console.log(view.getFloat32(1)); 8 | // expected output: 3.1415927410125732 9 | -------------------------------------------------------------------------------- /dataview/dataview-setfloat64.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setFloat64(1, Math.PI); 6 | 7 | console.log(view.getFloat64(1)); 8 | // expected output: 3.141592653589793 9 | -------------------------------------------------------------------------------- /dataview/dataview-setint8.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setInt8(1, 127); // (max signed 8-bit integer) 6 | 7 | console.log(view.getInt8(1)); 8 | // expected output: 127 9 | -------------------------------------------------------------------------------- /date/date-setutcminutes.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00'); 2 | 3 | console.log(date1.getUTCMinutes()); 4 | // expected output: 15 5 | 6 | date1.setUTCMinutes(25); 7 | 8 | console.log(date1.getUTCMinutes()); 9 | // expected output: 25 10 | -------------------------------------------------------------------------------- /date/date-setutcseconds.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00'); 2 | 3 | console.log(date1.getUTCSeconds()); 4 | // expected output: 30 5 | 6 | date1.setUTCSeconds(39); 7 | 8 | console.log(date1.getUTCSeconds()); 9 | // expected output: 39 10 | -------------------------------------------------------------------------------- /globalprops/globalprops-nan.js: -------------------------------------------------------------------------------- 1 | function sanitise(x) { 2 | if (isNaN(x)) { 3 | return NaN; 4 | } 5 | return x; 6 | } 7 | 8 | console.log(sanitise('1')); 9 | // expected output: "1" 10 | 11 | console.log(sanitise('NotANumber')); 12 | // expected output: NaN 13 | -------------------------------------------------------------------------------- /math/math-sign.js: -------------------------------------------------------------------------------- 1 | console.log(Math.sign(3)); 2 | // expected output: 1 3 | 4 | console.log(Math.sign(-3)); 5 | // expected output: -1 6 | 7 | console.log(Math.sign(0)); 8 | // expected output: 0 9 | 10 | console.log(Math.sign('-3')); 11 | // expected output: -1 12 | -------------------------------------------------------------------------------- /object/object-defineproperties.js: -------------------------------------------------------------------------------- 1 | const object1 = {}; 2 | 3 | Object.defineProperties(object1, { 4 | property1: { 5 | value: 42, 6 | writable: true 7 | }, 8 | property2: {} 9 | }); 10 | 11 | console.log(object1.property1); 12 | // expected output: 42 13 | -------------------------------------------------------------------------------- /promise/promise-reject.js: -------------------------------------------------------------------------------- 1 | function resolved(result) { 2 | console.log('Resolved'); 3 | } 4 | 5 | function rejected(result) { 6 | console.error(result); 7 | } 8 | 9 | Promise.reject(new Error('fail')).then(resolved, rejected); 10 | // expected output: Error: fail 11 | -------------------------------------------------------------------------------- /reflect/reflect-get.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | x: 1, 3 | y: 2 4 | }; 5 | 6 | console.log(Reflect.get(object1, 'x')); 7 | // expected output: 1 8 | 9 | const array1 = ['zero', 'one']; 10 | 11 | console.log(Reflect.get(array1, 1)); 12 | // expected output: "one" 13 | -------------------------------------------------------------------------------- /reflect/reflect-preventextensions.js: -------------------------------------------------------------------------------- 1 | const object1 = {}; 2 | 3 | console.log(Reflect.isExtensible(object1)); 4 | // expected output: true 5 | 6 | Reflect.preventExtensions(object1); 7 | 8 | console.log(Reflect.isExtensible(object1)); 9 | // expected output: false 10 | -------------------------------------------------------------------------------- /set/set-prototype-constructor.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set([1, 2, 3, 4, 5]); 2 | 3 | console.log(set1.has(1)); 4 | // expected output: true 5 | 6 | console.log(set1.has(5)); 7 | // expected output: true 8 | 9 | console.log(set1.has(6)); 10 | // expected output: false 11 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-unscopables.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | object1[Symbol.unscopables] = { 6 | property1: true 7 | }; 8 | 9 | with (object1) { 10 | console.log(property1); 11 | // expected output: Error: property1 is not defined 12 | } 13 | -------------------------------------------------------------------------------- /array/array-iterator.js: -------------------------------------------------------------------------------- 1 | const array1 = ['a', 'b', 'c']; 2 | const iterator1 = array1[Symbol.iterator](); 3 | 4 | for (const value of iterator1) { 5 | console.log(value); 6 | } 7 | 8 | // expected output: "a" 9 | // expected output: "b" 10 | // expected output: "c" 11 | -------------------------------------------------------------------------------- /dataview/dataview-getuint8.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setUint8(1, 255); // (max unsigned 8-bit integer) 6 | 7 | console.log(view.getUint8(1)); 8 | // expected output: 255 9 | -------------------------------------------------------------------------------- /dataview/dataview-setuint8.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setUint8(1, 255); // (max unsigned 8-bit integer) 6 | 7 | console.log(view.getUint8(1)); 8 | // expected output: 255 9 | -------------------------------------------------------------------------------- /expressions/expressions-greater-than.js: -------------------------------------------------------------------------------- 1 | console.log(5 > 3); 2 | // expected output: true 3 | 4 | console.log(3 > 3); 5 | // expected output: false 6 | 7 | console.log(3n > 5); 8 | // expected output: false 9 | 10 | console.log('ab' > 'aa'); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /expressions/expressions-less-than.js: -------------------------------------------------------------------------------- 1 | console.log(5 < 3); 2 | // expected output: false 3 | 4 | console.log(3 < 3); 5 | // expected output: false 6 | 7 | console.log(3n < 5); 8 | // expected output: true 9 | 10 | console.log('aa' < 'ab'); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /math/math-ceil.js: -------------------------------------------------------------------------------- 1 | console.log(Math.ceil(.95)); 2 | // expected output: 1 3 | 4 | console.log(Math.ceil(4)); 5 | // expected output: 4 6 | 7 | console.log(Math.ceil(7.004)); 8 | // expected output: 8 9 | 10 | console.log(Math.ceil(-7.004)); 11 | // expected output: -7 12 | -------------------------------------------------------------------------------- /regexp/regexp-prototype-@@replace.js: -------------------------------------------------------------------------------- 1 | class RegExp1 extends RegExp { 2 | [Symbol.replace](str) { 3 | return RegExp.prototype[Symbol.replace].call(this, str, '#!@?'); 4 | } 5 | } 6 | 7 | console.log('football'.replace(new RegExp1('foo'))); 8 | // expected output: "#!@?tball" 9 | -------------------------------------------------------------------------------- /string/string-includes.js: -------------------------------------------------------------------------------- 1 | const sentence = 'The quick brown fox jumps over the lazy dog.'; 2 | 3 | const word = 'fox'; 4 | 5 | console.log(`The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence`); 6 | // expected output: "The word "fox" is in the sentence" 7 | -------------------------------------------------------------------------------- /ALGO/once/Readme.md: -------------------------------------------------------------------------------- 1 | # Once 2 | 3 | Write a function that accepts a function as it's only argument and returns a new function that can only ever be executed once. 4 | 5 | Once completed, add a second arguments that allows the function to be executed `x` number of times before it stops working. 6 | -------------------------------------------------------------------------------- /Recursion/binary-search/binary-search.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 2 | 3 | function rBsearch(array, targetVal) { 4 | if (arr.length === 0) { 5 | return false; 6 | } 7 | } 8 | const midIdx = Math.floor(array.length / 2); 9 | if (target === midIdx) return midIdx; 10 | -------------------------------------------------------------------------------- /dataview/dataview-getint16.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setInt16(1, 32767); // (max signed 16-bit integer) 6 | 7 | console.log(view.getInt16(1)); 8 | // expected output: 32767 9 | -------------------------------------------------------------------------------- /dataview/dataview-setint16.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setInt16(1, 32767); // (max signed 16-bit integer) 6 | 7 | console.log(view.getInt16(1)); 8 | // expected output: 32767 9 | -------------------------------------------------------------------------------- /date/date-getutcdate.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('August 19, 1975 23:15:30 GMT+11:00'); 2 | const date2 = new Date('August 19, 1975 23:15:30 GMT-11:00'); 3 | 4 | console.log(date1.getUTCDate()); 5 | // expected output: 19 6 | 7 | console.log(date2.getUTCDate()); 8 | // expected output: 20 9 | -------------------------------------------------------------------------------- /date/date-parse.js: -------------------------------------------------------------------------------- 1 | const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT'); 2 | const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT'); 3 | 4 | console.log(unixTimeZero); 5 | // expected output: 0 6 | 7 | console.log(javaScriptRelease); 8 | // expected output: 818035920000 9 | -------------------------------------------------------------------------------- /date/date-setutcmilliseconds.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('2018-01-24T12:38:29.069Z'); 2 | 3 | console.log(date1.getUTCMilliseconds()); 4 | // expected output: 69 5 | 6 | date1.setUTCMilliseconds(420); 7 | 8 | console.log(date1.getUTCMilliseconds()); 9 | // expected output: 420 10 | -------------------------------------------------------------------------------- /expressions/expressions-functionasteriskexpression.js: -------------------------------------------------------------------------------- 1 | function* foo() { 2 | yield 'a'; 3 | yield 'b'; 4 | yield 'c'; 5 | } 6 | 7 | let str = ''; 8 | for (const val of foo()) { 9 | str = str + val; 10 | } 11 | 12 | console.log(str); 13 | // expected output: "abc" 14 | -------------------------------------------------------------------------------- /math/math-cbrt.js: -------------------------------------------------------------------------------- 1 | console.log(Math.cbrt(-1)); 2 | // expected output: -1 3 | 4 | console.log(Math.cbrt(1)); 5 | // expected output: 1 6 | 7 | console.log(Math.cbrt(Infinity)); 8 | // expected output: Infinity 9 | 10 | console.log(Math.cbrt(64)); 11 | // expected output: 4 12 | -------------------------------------------------------------------------------- /math/math-floor.js: -------------------------------------------------------------------------------- 1 | console.log(Math.floor(5.95)); 2 | // expected output: 5 3 | 4 | console.log(Math.floor(5.05)); 5 | // expected output: 5 6 | 7 | console.log(Math.floor(5)); 8 | // expected output: 5 9 | 10 | console.log(Math.floor(-5.05)); 11 | // expected output: -6 12 | -------------------------------------------------------------------------------- /math/math-log.js: -------------------------------------------------------------------------------- 1 | function getBaseLog(x, y) { 2 | return Math.log(y) / Math.log(x); 3 | } 4 | 5 | // 2 x 2 x 2 = 8 6 | console.log(getBaseLog(2, 8)); 7 | // expected output: 3 8 | 9 | // 5 x 5 x 5 x 5 = 625 10 | console.log(getBaseLog(5, 625)); 11 | // expected output: 4 12 | -------------------------------------------------------------------------------- /math/math-round.js: -------------------------------------------------------------------------------- 1 | console.log(Math.round(0.9)); 2 | // expected output: 1 3 | 4 | console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05)); 5 | // expected output: 6 6 5 6 | 7 | console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95)); 8 | // expected output: -5 -5 -6 9 | -------------------------------------------------------------------------------- /number/number-valueof.js: -------------------------------------------------------------------------------- 1 | const numObj = new Number(42); 2 | console.log(typeof numObj); 3 | // expected output: "object" 4 | 5 | const num = numObj.valueOf(); 6 | console.log(num); 7 | // expected output: 42 8 | 9 | console.log(typeof num); 10 | // expected output: "number" 11 | -------------------------------------------------------------------------------- /statement/statement-ifelse.js: -------------------------------------------------------------------------------- 1 | function testNum(a) { 2 | let result; 3 | if (a > 0) { 4 | result = 'positive'; 5 | } else { 6 | result = 'NOT positive'; 7 | } 8 | return result; 9 | } 10 | 11 | console.log(testNum(-5)); 12 | // expected output: "NOT positive" 13 | -------------------------------------------------------------------------------- /string/string-charcodeat.js: -------------------------------------------------------------------------------- 1 | const sentence = 'The quick brown fox jumps over the lazy dog.'; 2 | 3 | const index = 4; 4 | 5 | console.log(`The character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(index)}`); 6 | // expected output: "The character code 113 is equal to q" 7 | -------------------------------------------------------------------------------- /string/string-localecompare.js: -------------------------------------------------------------------------------- 1 | const a = 'réservé'; // with accents, lowercase 2 | const b = 'RESERVE'; // no accents, uppercase 3 | 4 | console.log(a.localeCompare(b)); 5 | // expected output: 1 6 | console.log(a.localeCompare(b, 'en', { sensitivity: 'base' })); 7 | // expected output: 0 8 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/CopyMachine.js: -------------------------------------------------------------------------------- 1 | //Copy an Array 2 | function CopyMachine(arr, num) { 3 | let newArr = []; 4 | while (num >= 1) { 5 | newArr.push([...arr]); //using spread operator 6 | num--; 7 | } 8 | return newArr; 9 | } 10 | 11 | console.log(CopyMachine(["hello", "world"], 2)); 12 | -------------------------------------------------------------------------------- /ALGO/__PYTHON/once.py: -------------------------------------------------------------------------------- 1 | class once: 2 | def __init__(self, func, times=1): 3 | self.times = int(times) 4 | self.func = func 5 | def __call__(self, *args, **kwargs): 6 | if self.times > 0: 7 | self.times -= 1 8 | return self.func(*args, **kwargs) 9 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-search.js: -------------------------------------------------------------------------------- 1 | class Search1 { 2 | constructor(value) { 3 | this.value = value; 4 | } 5 | [Symbol.search](string) { 6 | return string.indexOf(this.value); 7 | } 8 | } 9 | 10 | console.log('foobar'.search(new Search1('bar'))); 11 | // expected output: 3 12 | -------------------------------------------------------------------------------- /Dynamic-Programming/dynamic-time-warping/lib/distanceFunctions/manhattan.js: -------------------------------------------------------------------------------- 1 | const distance = (x, y) => { 2 | const difference = x - y; 3 | const manhattanDistance = Math.abs(difference); 4 | return manhattanDistance; 5 | }; 6 | 7 | module.exports = { 8 | distance: distance, 9 | }; 10 | -------------------------------------------------------------------------------- /SANDBOX/move-zeroes.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/move-zeroes/ 2 | // Author : Bryan Guner 3 | 4 | var moveZeroes = function (nums) { 5 | for (var i = nums.length; i--; ) { 6 | if (!nums[i]) { 7 | nums.splice(i, 1); 8 | nums.push(0); 9 | } 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /SANDBOX/valid-number.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/valid-number/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {string} s 6 | * @return {boolean} 7 | */ 8 | var isNumber = function (s) { 9 | if (s.trim() === "") return false; 10 | return !isNaN(Number(s)); 11 | }; 12 | -------------------------------------------------------------------------------- /dataview/dataview-getuint16.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setUint16(1, 65535); // (max unsigned 16-bit integer) 6 | 7 | console.log(view.getUint16(1)); 8 | // expected output: 65535 9 | -------------------------------------------------------------------------------- /dataview/dataview-setuint16.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setUint16(1, 65535); // (max unsigned 16-bit integer) 6 | 7 | console.log(view.getUint16(1)); 8 | // expected output: 65535 9 | -------------------------------------------------------------------------------- /date/date-setmonth.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | event.setMonth(3); 4 | 5 | console.log(event.getMonth()); 6 | // expected output: 3 7 | 8 | console.log(event); 9 | // Sat Apr 19 1975 23:15:30 GMT+0100 (CET) 10 | // (note: your timezone may vary) 11 | -------------------------------------------------------------------------------- /expressions/expressions-equality.js: -------------------------------------------------------------------------------- 1 | console.log(1 == 1); 2 | // expected output: true 3 | 4 | console.log('hello' == 'hello'); 5 | // expected output: true 6 | 7 | console.log('1' == 1); 8 | // expected output: true 9 | 10 | console.log(0 == false); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /expressions/expressions-exponentiation.js: -------------------------------------------------------------------------------- 1 | console.log(3 ** 4); 2 | // expected output: 81 3 | 4 | console.log(10 ** -2); 5 | // expected output: 0.01 6 | 7 | console.log(2 ** 3 ** 2); 8 | // expected output: 512 9 | 10 | console.log((2 ** 3) ** 2); 11 | // expected output: 64 12 | -------------------------------------------------------------------------------- /expressions/expressions-less-than-or-equal.js: -------------------------------------------------------------------------------- 1 | console.log(5 <= 3); 2 | // expected output: false 3 | 4 | console.log(3 <= 3); 5 | // expected output: true 6 | 7 | console.log(3n <= 5); 8 | // expected output: true 9 | 10 | console.log('aa' <= 'ab'); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /functions/functions-setter.js: -------------------------------------------------------------------------------- 1 | const language = { 2 | set current(name) { 3 | this.log.push(name); 4 | }, 5 | log: [] 6 | }; 7 | 8 | language.current = 'EN'; 9 | language.current = 'FA'; 10 | 11 | console.log(language.log); 12 | // expected output: Array ["EN", "FA"] 13 | -------------------------------------------------------------------------------- /globalprops/globalprops-encodeuricomponent.js: -------------------------------------------------------------------------------- 1 | // encodes characters such as ?,=,/,&,: 2 | console.log(`?x=${encodeURIComponent('test?')}`); 3 | // expected output: "?x=test%3F" 4 | 5 | console.log(`?x=${encodeURIComponent('шеллы')}`); 6 | // expected output: "?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B" 7 | -------------------------------------------------------------------------------- /math/math-log2.js: -------------------------------------------------------------------------------- 1 | console.log(Math.log2(3)); 2 | // expected output: 1.584962500721156 3 | 4 | console.log(Math.log2(2)); 5 | // expected output: 1 6 | 7 | console.log(Math.log2(1)); 8 | // expected output: 0 9 | 10 | console.log(Math.log2(0)); 11 | // expected output: -Infinity 12 | -------------------------------------------------------------------------------- /math/math-trunc.js: -------------------------------------------------------------------------------- 1 | console.log(Math.trunc(13.37)); 2 | // expected output: 13 3 | 4 | console.log(Math.trunc(42.84)); 5 | // expected output: 42 6 | 7 | console.log(Math.trunc(0.123)); 8 | // expected output: 0 9 | 10 | console.log(Math.trunc(-0.123)); 11 | // expected output: -0 12 | -------------------------------------------------------------------------------- /number/number-tostring.js: -------------------------------------------------------------------------------- 1 | function hexColour(c) { 2 | if (c < 256) { 3 | return Math.abs(c).toString(16); 4 | } 5 | return 0; 6 | } 7 | 8 | console.log(hexColour(233)); 9 | // expected output: "e9" 10 | 11 | console.log(hexColour('11')); 12 | // expected output: "b" 13 | -------------------------------------------------------------------------------- /regexp/regexp-constructor.js: -------------------------------------------------------------------------------- 1 | const regex1 = /\w+/; 2 | const regex2 = new RegExp('\\w+'); 3 | 4 | console.log(regex1); 5 | // expected output: /\w+/ 6 | 7 | console.log(regex2); 8 | // expected output: /\w+/ 9 | 10 | console.log(regex1 === regex2); 11 | // expected output: false 12 | -------------------------------------------------------------------------------- /statement/statement-functionasterisk.js: -------------------------------------------------------------------------------- 1 | function* generator(i) { 2 | yield i; 3 | yield i + 10; 4 | } 5 | 6 | const gen = generator(10); 7 | 8 | console.log(gen.next().value); 9 | // expected output: 10 10 | 11 | console.log(gen.next().value); 12 | // expected output: 20 13 | -------------------------------------------------------------------------------- /ALGO/flatten-array/in-place.js: -------------------------------------------------------------------------------- 1 | module.exports = (array) => { 2 | let i = 0; 3 | 4 | while (i < array.length) { 5 | if (Array.isArray(array[i])) { 6 | array.splice(...[i, 1].concat(array[i])); 7 | } else { 8 | i += 1; 9 | } 10 | } 11 | 12 | return array; 13 | }; 14 | -------------------------------------------------------------------------------- /ALGO/string-rotation/Readme.md: -------------------------------------------------------------------------------- 1 | # String Rotation 2 | 3 | Find out if a string is a rotation of another string. E.g. `ABCD` is a rotation of `BCDA` but not `ACBD`. 4 | 5 | ## Source 6 | 7 | [Reddit](http://www.reddit.com/r/javascript/comments/1ftyjh/common_code_problems_solved_in_javascript_xpost/cae25ra) 8 | -------------------------------------------------------------------------------- /ALGO/weakmap/weakmap-prototype-delete.js: -------------------------------------------------------------------------------- 1 | const weakmap1 = new WeakMap(); 2 | const object1 = {}; 3 | 4 | weakmap1.set(object1, 42); 5 | 6 | console.log(weakmap1.delete(object1)); 7 | // expected output: true 8 | 9 | console.log(weakmap1.has(object1)); 10 | // expected output: false 11 | -------------------------------------------------------------------------------- /Arrays/basic-examples/problems/reverse-string.js: -------------------------------------------------------------------------------- 1 | module.exports = function reverseString(string) { 2 | if (typeof string !== "string") { 3 | throw new TypeError( 4 | `reverseString requires a string not a ${typeof string}` 5 | ); 6 | } 7 | return [...string].reverse().join(""); 8 | }; 9 | -------------------------------------------------------------------------------- /dataview/dataview-getint32.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setInt32(1, 2147483647); // (max signed 32-bit integer) 6 | 7 | console.log(view.getInt32(1)); 8 | // expected output: 2147483647 9 | -------------------------------------------------------------------------------- /dataview/dataview-setint32.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setInt32(1, 2147483647); // (max signed 32-bit integer) 6 | 7 | console.log(view.getInt32(1)); 8 | // expected output: 2147483647 9 | -------------------------------------------------------------------------------- /date/date-getutchours.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00'); 2 | const date2 = new Date('December 31, 1975, 23:15:30 GMT-11:00'); 3 | 4 | console.log(date1.getUTCHours()); 5 | // expected output: 12 6 | 7 | console.log(date2.getUTCHours()); 8 | // expected output: 10 9 | -------------------------------------------------------------------------------- /date/date-setfullyear.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | event.setFullYear(1969); 4 | 5 | console.log(event.getFullYear()); 6 | // expected output: 1969 7 | 8 | event.setFullYear(0); 9 | 10 | console.log(event.getFullYear()); 11 | // expected output: 0 12 | -------------------------------------------------------------------------------- /date/date-todatestring.js: -------------------------------------------------------------------------------- 1 | const event = new Date(1993, 6, 28, 14, 39, 7); 2 | 3 | console.log(event.toString()); 4 | // expected output: Wed Jul 28 1993 14:39:07 GMT+0200 (CEST) 5 | // (note: your timezone may vary) 6 | 7 | console.log(event.toDateString()); 8 | // expected output: Wed Jul 28 1993 9 | -------------------------------------------------------------------------------- /date/date-valueof.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5)); 2 | 3 | console.log(date1.valueOf()); 4 | // expected output: 823230245000 5 | 6 | const date2 = new Date('02 Feb 1996 03:04:05 GMT'); 7 | 8 | console.log(date2.valueOf()); 9 | // expected output: 823230245000 10 | -------------------------------------------------------------------------------- /expressions/expressions-greater-than-or-equal.js: -------------------------------------------------------------------------------- 1 | console.log(5 >= 3); 2 | // expected output: true 3 | 4 | console.log(3 >= 3); 5 | // expected output: true 6 | 7 | console.log(3n >= 5); 8 | // expected output: false 9 | 10 | console.log('ab' >= 'aa'); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /functions/functions-arguments.js: -------------------------------------------------------------------------------- 1 | function func1(a, b, c) { 2 | console.log(arguments[0]); 3 | // expected output: 1 4 | 5 | console.log(arguments[1]); 6 | // expected output: 2 7 | 8 | console.log(arguments[2]); 9 | // expected output: 3 10 | } 11 | 12 | func1(1, 2, 3); 13 | -------------------------------------------------------------------------------- /Dynamic-Programming/dynamic-time-warping/lib/distanceFunctions/euclidean.js: -------------------------------------------------------------------------------- 1 | const distance = (x, y) => { 2 | const difference = x - y; 3 | const euclideanDistance = Math.sqrt(difference * difference); 4 | return euclideanDistance; 5 | }; 6 | 7 | module.exports = { 8 | distance: distance, 9 | }; 10 | -------------------------------------------------------------------------------- /SANDBOX/sort-colors.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/sort-colors/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number[]} nums 6 | * @return {void} Do not return anything, modify nums in-place instead. 7 | */ 8 | 9 | var sortColors = function (nums) { 10 | nums.sort(); 11 | }; 12 | -------------------------------------------------------------------------------- /_Extra-Practice/30-days-of-code-master/day2_operators.py: -------------------------------------------------------------------------------- 1 | mealCost = float(input()) 2 | tipPercent = int(input()) 3 | taxPercent = int(input()) 4 | 5 | totalCost = mealCost + (mealCost * (tipPercent/100)) + (mealCost * (taxPercent/100)) 6 | 7 | print('The total meal cost is', round(totalCost), 'dollars.') 8 | -------------------------------------------------------------------------------- /dataview/dataview-getuint32.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setUint32(1, 4294967295); // (max unsigned 32-bit integer) 6 | 7 | console.log(view.getUint32(1)); 8 | // expected output: 4294967295 9 | -------------------------------------------------------------------------------- /dataview/dataview-setuint32.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view = new DataView(buffer); 5 | view.setUint32(1, 4294967295); // (max unsigned 32-bit integer) 6 | 7 | console.log(view.getUint32(1)); 8 | // expected output: 4294967295 9 | -------------------------------------------------------------------------------- /date/date-setseconds.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | event.setSeconds(42); 4 | 5 | console.log(event.getSeconds()); 6 | // expected output: 42 7 | 8 | console.log(event); 9 | // Sat Apr 19 1975 23:15:42 GMT+0100 (CET) 10 | // (note: your timezone may vary) 11 | -------------------------------------------------------------------------------- /date/date-toisostring.js: -------------------------------------------------------------------------------- 1 | const event = new Date('05 October 2011 14:48 UTC'); 2 | console.log(event.toString()); 3 | // expected output: Wed Oct 05 2011 16:48:00 GMT+0200 (CEST) 4 | // (note: your timezone may vary) 5 | 6 | console.log(event.toISOString()); 7 | // expected output: 2011-10-05T14:48:00.000Z 8 | -------------------------------------------------------------------------------- /expressions/expressions-inequality.js: -------------------------------------------------------------------------------- 1 | console.log(1 != 1); 2 | // expected output: false 3 | 4 | console.log('hello' != 'hello'); 5 | // expected output: false 6 | 7 | console.log('1' != 1); 8 | // expected output: false 9 | 10 | console.log(0 != false); 11 | // expected output: false 12 | -------------------------------------------------------------------------------- /math/math-log10.js: -------------------------------------------------------------------------------- 1 | console.log(Math.log10(100000)); 2 | // expected output: 5 3 | 4 | console.log(Math.log10(2)); 5 | // expected output: 0.3010299956639812 6 | 7 | console.log(Math.log10(1)); 8 | // expected output: 0 9 | 10 | console.log(Math.log10(0)); 11 | // expected output: -Infinity 12 | -------------------------------------------------------------------------------- /math/math-log1p.js: -------------------------------------------------------------------------------- 1 | console.log(Math.log1p(1)); 2 | // expected output: 0.6931471805599453 3 | 4 | console.log(Math.log1p(0)); 5 | // expected output: 0 6 | 7 | console.log(Math.log1p(-1)); 8 | // expected output: -Infinity 9 | 10 | console.log(Math.log1p(-2)); 11 | // expected output: NaN 12 | -------------------------------------------------------------------------------- /object/object-prototype-valueof.js: -------------------------------------------------------------------------------- 1 | function MyNumberType(n) { 2 | this.number = n; 3 | } 4 | 5 | MyNumberType.prototype.valueOf = function() { 6 | return this.number; 7 | }; 8 | 9 | const object1 = new MyNumberType(4); 10 | 11 | console.log(object1 + 3); 12 | // expected output: 7 13 | -------------------------------------------------------------------------------- /reflect/reflect-getprototypeof.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | const proto1 = Reflect.getPrototypeOf(object1); 6 | 7 | console.log(proto1); 8 | // expected output: [object Object] 9 | 10 | console.log(Reflect.getPrototypeOf(proto1)); 11 | // expected output: null 12 | -------------------------------------------------------------------------------- /SANDBOX/bulb-switcher.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/bulb-switcher/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number} n 6 | * @return {number} 7 | */ 8 | 9 | // 打表 10 | var bulbSwitch = function (n) { 11 | var ans = -1 + Math.sqrt(1 + n); 12 | return Math.ceil(ans); 13 | }; 14 | -------------------------------------------------------------------------------- /SANDBOX/power-of-two.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/power-of-two/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number} n 6 | * @return {boolean} 7 | */ 8 | 9 | var isPowerOfTwo = function (n) { 10 | var tmp = ~~(Math.log(n) / Math.log(2)); 11 | return n === 1 << tmp; 12 | }; 13 | -------------------------------------------------------------------------------- /date/date-getutcfullyear.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00'); 2 | const date2 = new Date('December 31, 1975, 23:15:30 GMT-11:00'); 3 | 4 | console.log(date1.getUTCFullYear()); 5 | // expected output: 1975 6 | 7 | console.log(date2.getUTCFullYear()); 8 | // expected output: 1976 9 | -------------------------------------------------------------------------------- /date/date-setdate.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | event.setDate(24); 4 | 5 | console.log(event.getDate()); 6 | // expected output: 24 7 | 8 | event.setDate(32); 9 | // Only 31 days in August! 10 | 11 | console.log(event.getDate()); 12 | // expected output: 1 13 | -------------------------------------------------------------------------------- /functions/functions-getter.js: -------------------------------------------------------------------------------- 1 | const obj = { 2 | log: ['a', 'b', 'c'], 3 | get latest() { 4 | if (this.log.length === 0) { 5 | return undefined; 6 | } 7 | return this.log[this.log.length - 1]; 8 | } 9 | }; 10 | 11 | console.log(obj.latest); 12 | // expected output: "c" 13 | -------------------------------------------------------------------------------- /functions/functions-restparameters.js: -------------------------------------------------------------------------------- 1 | function sum(...theArgs) { 2 | return theArgs.reduce((previous, current) => { 3 | return previous + current; 4 | }); 5 | } 6 | 7 | console.log(sum(1, 2, 3)); 8 | // expected output: 6 9 | 10 | console.log(sum(1, 2, 3, 4)); 11 | // expected output: 10 12 | -------------------------------------------------------------------------------- /map/map-prototype-keys.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | 3 | map1.set('0', 'foo'); 4 | map1.set(1, 'bar'); 5 | 6 | const iterator1 = map1.keys(); 7 | 8 | console.log(iterator1.next().value); 9 | // expected output: "0" 10 | 11 | console.log(iterator1.next().value); 12 | // expected output: 1 13 | -------------------------------------------------------------------------------- /math/math-hypot.js: -------------------------------------------------------------------------------- 1 | console.log(Math.hypot(3, 4)); 2 | // expected output: 5 3 | 4 | console.log(Math.hypot(5, 12)); 5 | // expected output: 13 6 | 7 | console.log(Math.hypot(3, 4, 5)); 8 | // expected output: 7.0710678118654755 9 | 10 | console.log(Math.hypot(-5)); 11 | // expected output: 5 12 | -------------------------------------------------------------------------------- /math/math-imul.js: -------------------------------------------------------------------------------- 1 | console.log(Math.imul(3, 4)); 2 | // expected output: 12 3 | 4 | console.log(Math.imul(-5, 12)); 5 | // expected output: -60 6 | 7 | console.log(Math.imul(0xffffffff, 5)); 8 | // expected output: -5 9 | 10 | console.log(Math.imul(0xfffffffe, 5)); 11 | // expected output: -10 12 | -------------------------------------------------------------------------------- /object/object-defineproperty.js: -------------------------------------------------------------------------------- 1 | const object1 = {}; 2 | 3 | Object.defineProperty(object1, 'property1', { 4 | value: 42, 5 | writable: false 6 | }); 7 | 8 | object1.property1 = 77; 9 | // throws an error in strict mode 10 | 11 | console.log(object1.property1); 12 | // expected output: 42 13 | -------------------------------------------------------------------------------- /object/object-entries.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | a: 'somestring', 3 | b: 42 4 | }; 5 | 6 | for (const [key, value] of Object.entries(object1)) { 7 | console.log(`${key}: ${value}`); 8 | } 9 | 10 | // expected output: 11 | // "a: somestring" 12 | // "b: 42" 13 | // order is not guaranteed 14 | -------------------------------------------------------------------------------- /object/object-prototype-tostring.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | const dog1 = new Dog('Gabby'); 6 | 7 | Dog.prototype.toString = function dogToString() { 8 | return `${this.name}`; 9 | }; 10 | 11 | console.log(dog1.toString()); 12 | // expected output: "Gabby" 13 | -------------------------------------------------------------------------------- /set/set-prototype-values.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | set1.add(42); 3 | set1.add('forty two'); 4 | 5 | const iterator1 = set1.values(); 6 | 7 | console.log(iterator1.next().value); 8 | // expected output: 42 9 | 10 | console.log(iterator1.next().value); 11 | // expected output: "forty two" 12 | -------------------------------------------------------------------------------- /ALGO/squareofnumber.js: -------------------------------------------------------------------------------- 1 | // Complete the square sum method so that it squares each number passed into it and then sums the results together. 2 | 3 | function squareSum(numbers){ 4 | const sumSquare = numbers.map(x => x * x).reduce(function(result, item) { 5 | return result + item; 6 | }, 0); 7 | return sumSquare; 8 | } -------------------------------------------------------------------------------- /ALGO/symbol/symbol-replace.js: -------------------------------------------------------------------------------- 1 | class Replace1 { 2 | constructor(value) { 3 | this.value = value; 4 | } 5 | [Symbol.replace](string) { 6 | return `s/${string}/${this.value}/g`; 7 | } 8 | } 9 | 10 | console.log('foo'.replace(new Replace1('bar'))); 11 | // expected output: "s/foo/bar/g" 12 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-filter.js: -------------------------------------------------------------------------------- 1 | function isNegative(element, index, array) { 2 | return element < 0; 3 | } 4 | 5 | const int8 = new Int8Array([-10, 20, -30, 40, -50]); 6 | const negInt8 = int8.filter(isNegative); 7 | 8 | console.log(negInt8); 9 | // expected output: Int8Array [-10, -30, -50] 10 | -------------------------------------------------------------------------------- /ALGO/weakset/weakset-prototype-has.js: -------------------------------------------------------------------------------- 1 | const weakset1 = new WeakSet(); 2 | const object1 = {}; 3 | const object2 = {}; 4 | 5 | weakset1.add(object1); 6 | 7 | console.log(weakset1.has(object1)); 8 | // expected output: true 9 | 10 | console.log(weakset1.has(object2)); 11 | // expected output: false 12 | -------------------------------------------------------------------------------- /Dynamic-Programming/dynamic-time-warping/lib/distanceFunctions/squaredEuclidean.js: -------------------------------------------------------------------------------- 1 | const distance = (x, y) => { 2 | const difference = x - y; 3 | const squaredEuclideanDistance = difference * difference; 4 | return squaredEuclideanDistance; 5 | }; 6 | 7 | module.exports = { 8 | distance: distance, 9 | }; 10 | -------------------------------------------------------------------------------- /SANDBOX/palindrome-number.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/palindrome-number/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number} x 6 | * @return {boolean} 7 | */ 8 | 9 | var isPalindrome = function (x) { 10 | return x.toString() == x.toString().split("").reverse().join(""); 11 | }; 12 | -------------------------------------------------------------------------------- /SANDBOX/reverse-string.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/reverse-string/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {string} s 6 | * @return {string} 7 | */ 8 | var reverseString = function (s) { 9 | if (s === null) return s; 10 | 11 | return s.split("").reverse().join(""); 12 | }; 13 | -------------------------------------------------------------------------------- /SANDBOX/sqrtx.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/sqrtx/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number} x 6 | * @return {number} 7 | */ 8 | 9 | // I really do not know what the meaning of this problem is 10 | var mySqrt = function (x) { 11 | return Math.floor(Math.sqrt(x)); 12 | }; 13 | -------------------------------------------------------------------------------- /_Extra-Practice/30-days-of-code-master/day7_arrays.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | 6 | n = int(input().strip()) 7 | arr = [int(arr_temp) for arr_temp in input().strip().split(' ')] 8 | 9 | arr.reverse() 10 | 11 | arrstring = ' '.join(str(e) for e in arr) 12 | 13 | print(arrstring) 14 | -------------------------------------------------------------------------------- /expressions/expressions-deleteoperator.js: -------------------------------------------------------------------------------- 1 | const Employee = { 2 | firstname: 'John', 3 | lastname: 'Doe' 4 | }; 5 | 6 | console.log(Employee.firstname); 7 | // expected output: "John" 8 | 9 | delete Employee.firstname; 10 | 11 | console.log(Employee.firstname); 12 | // expected output: undefined 13 | -------------------------------------------------------------------------------- /globalprops/globalprops-infinity.js: -------------------------------------------------------------------------------- 1 | const maxNumber = Math.pow(10, 1000); // max positive number 2 | 3 | if (maxNumber === Infinity) { 4 | console.log('Let\'s call it Infinity!'); 5 | // expected output: "Let's call it Infinity!" 6 | } 7 | 8 | console.log(1 / maxNumber); 9 | // expected output: 0 10 | -------------------------------------------------------------------------------- /math/math-tanh.js: -------------------------------------------------------------------------------- 1 | console.log(Math.tanh(-1)); 2 | // expected output: -0.7615941559557649 3 | 4 | console.log(Math.tanh(0)); 5 | // expected output: 0 6 | 7 | console.log(Math.tanh(Infinity)); 8 | // expected output: 1 9 | 10 | console.log(Math.tanh(1)); 11 | // expected output: 0.7615941559557649 12 | -------------------------------------------------------------------------------- /number/number-isinteger.js: -------------------------------------------------------------------------------- 1 | function fits(x, y) { 2 | if (Number.isInteger(y / x)) { 3 | return 'Fits!'; 4 | } 5 | return 'Does NOT fit!'; 6 | } 7 | 8 | console.log(fits(5, 10)); 9 | // expected output: "Fits!" 10 | 11 | console.log(fits(5, 11)); 12 | // expected output: "Does NOT fit!" 13 | -------------------------------------------------------------------------------- /ALGO/weakmap/weakmap-prototype-get.js: -------------------------------------------------------------------------------- 1 | const weakmap1 = new WeakMap(); 2 | const object1 = {}; 3 | const object2 = {}; 4 | 5 | weakmap1.set(object1, 42); 6 | 7 | console.log(weakmap1.get(object1)); 8 | // expected output: 42 9 | 10 | console.log(weakmap1.get(object2)); 11 | // expected output: undefined 12 | -------------------------------------------------------------------------------- /ALGO/weakmap/weakmap-prototype-has.js: -------------------------------------------------------------------------------- 1 | const weakmap1 = new WeakMap(); 2 | const object1 = {}; 3 | const object2 = {}; 4 | 5 | weakmap1.set(object1, 'foo'); 6 | 7 | console.log(weakmap1.has(object1)); 8 | // expected output: true 9 | 10 | console.log(weakmap1.has(object2)); 11 | // expected output: false 12 | -------------------------------------------------------------------------------- /SANDBOX/implement-strstr.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/implement-strstr/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {string} haystack 6 | * @param {string} needle 7 | * @return {number} 8 | */ 9 | var strStr = function (haystack, needle) { 10 | return haystack.search(needle); 11 | }; 12 | -------------------------------------------------------------------------------- /array/array-join.js: -------------------------------------------------------------------------------- 1 | const elements = ['Fire', 'Air', 'Water']; 2 | 3 | console.log(elements.join()); 4 | // expected output: "Fire,Air,Water" 5 | 6 | console.log(elements.join('')); 7 | // expected output: "FireAirWater" 8 | 9 | console.log(elements.join('-')); 10 | // expected output: "Fire-Air-Water" 11 | -------------------------------------------------------------------------------- /date/date-setminutes.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30'); 2 | 3 | event.setMinutes(45); 4 | 5 | console.log(event.getMinutes()); 6 | // expected output: 45 7 | 8 | console.log(event); 9 | // expected output: Tue Aug 19 1975 23:45:30 GMT+0200 (CEST) 10 | // (note: your timezone may vary) 11 | -------------------------------------------------------------------------------- /date/date-tojson.js: -------------------------------------------------------------------------------- 1 | const event = new Date('August 19, 1975 23:15:30 UTC'); 2 | 3 | const jsonDate = event.toJSON(); 4 | 5 | console.log(jsonDate); 6 | // expected output: 1975-08-19T23:15:30.000Z 7 | 8 | console.log(new Date(jsonDate).toUTCString()); 9 | // expected output: Tue, 19 Aug 1975 23:15:30 GMT 10 | -------------------------------------------------------------------------------- /map/map-prototype-values.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | 3 | map1.set('0', 'foo'); 4 | map1.set(1, 'bar'); 5 | 6 | const iterator1 = map1.values(); 7 | 8 | console.log(iterator1.next().value); 9 | // expected output: "foo" 10 | 11 | console.log(iterator1.next().value); 12 | // expected output: "bar" 13 | -------------------------------------------------------------------------------- /reflect/reflect-set.js: -------------------------------------------------------------------------------- 1 | const object1 = {}; 2 | Reflect.set(object1, 'property1', 42); 3 | 4 | console.log(object1.property1); 5 | // expected output: 42 6 | 7 | const array1 = ['duck', 'duck', 'duck']; 8 | Reflect.set(array1, 2, 'goose'); 9 | 10 | console.log(array1[2]); 11 | // expected output: "goose" 12 | -------------------------------------------------------------------------------- /regexp/regexp-lastindex.js: -------------------------------------------------------------------------------- 1 | const regex1 = new RegExp( 'foo', 'g' ); 2 | const str1 = 'table football, foosball'; 3 | 4 | regex1.test(str1); 5 | 6 | console.log(regex1.lastIndex); 7 | // expected output: 9 8 | 9 | regex1.test(str1); 10 | 11 | console.log(regex1.lastIndex); 12 | // expected output: 19 13 | -------------------------------------------------------------------------------- /set/set-prototype-entries.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | set1.add(42); 3 | set1.add('forty two'); 4 | 5 | const iterator1 = set1.entries(); 6 | 7 | for (const entry of iterator1) { 8 | console.log(entry); 9 | // expected output: [42, 42] 10 | // expected output: ["forty two", "forty two"] 11 | } 12 | -------------------------------------------------------------------------------- /statement/statement-return.js: -------------------------------------------------------------------------------- 1 | function getRectArea(width, height) { 2 | if (width > 0 && height > 0) { 3 | return width * height; 4 | } 5 | return 0; 6 | } 7 | 8 | console.log(getRectArea(3, 4)); 9 | // expected output: 12 10 | 11 | console.log(getRectArea(-3, 4)); 12 | // expected output: 0 13 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/remove-duplicates-from-string.js: -------------------------------------------------------------------------------- 1 | export default (string) => { 2 | let output = ""; 3 | const hash = {}; 4 | 5 | for (let i = 0; i < string.length; i++) { 6 | if (!hash[string[i]]) { 7 | output += string[i]; 8 | } 9 | hash[string[i]] = true; 10 | } 11 | 12 | return output; 13 | }; 14 | -------------------------------------------------------------------------------- /ALGO/memoization_project/test/util.js: -------------------------------------------------------------------------------- 1 | const catchStackOverflow = (fn, ...args) => { 2 | try { 3 | return fn(...args); 4 | } catch (err) { 5 | if (err instanceof RangeError) { 6 | throw new Error("Stack Overflow"); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = { 12 | catchStackOverflow, 13 | }; 14 | -------------------------------------------------------------------------------- /Arrays/basic-examples/problems/my-map.js: -------------------------------------------------------------------------------- 1 | function myMap(inputArray, callback) { 2 | const outputArray = []; 3 | for (let index = 0; index < inputArray.length; index++) { 4 | outputArray.push(callback(inputArray[index], index, inputArray)); 5 | } 6 | return outputArray; 7 | } 8 | 9 | module.exports = myMap; 10 | -------------------------------------------------------------------------------- /Recursion/recursion_project/test/util.js: -------------------------------------------------------------------------------- 1 | const catchStackOverflow = (fn, ...args) => { 2 | try { 3 | return fn(...args); 4 | } catch (err) { 5 | if (err instanceof RangeError) { 6 | throw new Error("Stack Overflow"); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = { 12 | catchStackOverflow, 13 | }; 14 | -------------------------------------------------------------------------------- /SANDBOX/find-minimum-in-rotated-sorted-array.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number[]} nums 6 | * @return {number} 7 | */ 8 | 9 | var findMin = function (nums) { 10 | return Math.min.apply(null, nums); 11 | }; 12 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/make-modular-program.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"), 2 | listmodule = require("./make-modular-module"); 3 | 4 | listmodule(process.argv[2], process.argv[3], (err, files) => { 5 | if (err) console.log(err); 6 | files.forEach((file) => { 7 | console.log(file); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /math/math-abs.js: -------------------------------------------------------------------------------- 1 | function difference(a, b) { 2 | return Math.abs(a - b); 3 | } 4 | 5 | console.log(difference(3, 5)); 6 | // expected output: 2 7 | 8 | console.log(difference(5, 3)); 9 | // expected output: 2 10 | 11 | console.log(difference(1.23456, 7.89012)); 12 | // expected output: 6.6555599999999995 13 | -------------------------------------------------------------------------------- /math/math-acosh.js: -------------------------------------------------------------------------------- 1 | console.log(Math.acosh(0.999999999999)); 2 | // expected output: NaN 3 | 4 | console.log(Math.acosh(1)); 5 | // expected output: 0 6 | 7 | console.log(Math.acosh(2)); 8 | // expected output: 1.3169578969248166 9 | 10 | console.log(Math.acosh(2.5)); 11 | // expected output: 1.566799236972411 12 | -------------------------------------------------------------------------------- /math/math-atanh.js: -------------------------------------------------------------------------------- 1 | console.log(Math.atanh(-1)); 2 | // expected output: -Infinity 3 | 4 | console.log(Math.atanh(0)); 5 | // expected output: 0 6 | 7 | console.log(Math.atanh(0.5)); 8 | // expected output: 0.549306144334055 (approximately) 9 | 10 | console.log(Math.atanh(1)); 11 | // expected output: Infinity 12 | -------------------------------------------------------------------------------- /math/math-expm1.js: -------------------------------------------------------------------------------- 1 | console.log(Math.expm1(0)); 2 | // expected output: 0 3 | 4 | console.log(Math.expm1(1)); 5 | // expected output: 1.718281828459045 6 | 7 | console.log(Math.expm1(-1)); 8 | // expected output: -0.6321205588285577 9 | 10 | console.log(Math.expm1(2)); 11 | // expected output: 6.38905609893065 12 | -------------------------------------------------------------------------------- /math/math-fround.js: -------------------------------------------------------------------------------- 1 | console.log(Math.fround(5.5)); 2 | // expected output: 5.5 3 | 4 | console.log(Math.fround(5.05)); 5 | // expected output: 5.050000190734863 6 | 7 | console.log(Math.fround(5)); 8 | // expected output: 5 9 | 10 | console.log(Math.fround(-5.05)); 11 | // expected output: -5.050000190734863 12 | -------------------------------------------------------------------------------- /math/math-sinh.js: -------------------------------------------------------------------------------- 1 | console.log(Math.sinh(0)); 2 | // expected output: 0 3 | 4 | console.log(Math.sinh(1)); 5 | // expected output: 1.1752011936438014 6 | 7 | console.log(Math.sinh(-1)); 8 | // expected output: -1.1752011936438014 9 | 10 | console.log(Math.sinh(2)); 11 | // expected output: 3.626860407847019 12 | -------------------------------------------------------------------------------- /set/set-prototype-delete.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | set1.add({ x: 10, y: 20 }).add({ x: 20, y: 30 }); 3 | 4 | // Delete any point with `x > 10`. 5 | set1.forEach((point) => { 6 | if (point.x > 10) { 7 | set1.delete(point); 8 | } 9 | }); 10 | 11 | console.log(set1.size); 12 | // expected output: 1 13 | -------------------------------------------------------------------------------- /ALGO/flatten-array/copy.js: -------------------------------------------------------------------------------- 1 | module.exports = function flatten(array) { 2 | const copy = []; 3 | 4 | for (let i = 0; i < array.length; i++) { 5 | if (Array.isArray(array[i])) { 6 | copy.push(...flatten(array[i])); 7 | } else { 8 | copy.push(array[i]); 9 | } 10 | } 11 | 12 | return copy; 13 | }; 14 | -------------------------------------------------------------------------------- /ALGO/symbol/symbol-for.js: -------------------------------------------------------------------------------- 1 | console.log(Symbol.for('bar') === Symbol.for('bar')); 2 | // expected output: true 3 | 4 | console.log(Symbol('bar') === Symbol('bar')); 5 | // expected output: false 6 | 7 | const symbol1 = Symbol.for('foo'); 8 | 9 | console.log(symbol1.toString()); 10 | // expected output: "Symbol(foo)" 11 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-join.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | 3 | console.log(uint8.join()); 4 | // expected output: "10,20,30,40,50" 5 | 6 | console.log(uint8.join('')); 7 | // expected output: "1020304050" 8 | 9 | console.log(uint8.join('-')); 10 | // expected output: "10-20-30-40-50" 11 | -------------------------------------------------------------------------------- /ALGO/weakset/weakset-prototype-delete.js: -------------------------------------------------------------------------------- 1 | const weakset1 = new WeakSet(); 2 | const object1 = {}; 3 | 4 | weakset1.add(object1); 5 | 6 | console.log(weakset1.has(object1)); 7 | // expected output: true 8 | 9 | weakset1.delete(object1); 10 | 11 | console.log(weakset1.has(object1)); 12 | // expected output: false 13 | -------------------------------------------------------------------------------- /SANDBOX/find-minimum-in-rotated-sorted-array-ii.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {number[]} nums 6 | * @return {number} 7 | */ 8 | 9 | var findMin = function (nums) { 10 | return Math.min.apply(null, nums); 11 | }; 12 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/basic-algorithm/07-confirm-ending.js: -------------------------------------------------------------------------------- 1 | function confirmEnding(str, target) { 2 | // length of target string, substr length - length of target, === 3 | if (target === str.substr(0 - target.length)) { 4 | return true; 5 | } else return false; 6 | } 7 | 8 | console.log(confirmEnding("Bastian", "n")); 9 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/intermediate-algorithm/17-steamroller.js: -------------------------------------------------------------------------------- 1 | function steamrollArray(arr) { 2 | if (Array.isArray(arr)) { 3 | return arr.reduce((done, curr) => done.concat(steamrollArray(curr)), []); 4 | } else { 5 | return arr; 6 | } 7 | } 8 | 9 | console.log(steamrollArray([1, [2], [3, [[4]]]])); 10 | -------------------------------------------------------------------------------- /array/array-includes.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 2, 3]; 2 | 3 | console.log(array1.includes(2)); 4 | // expected output: true 5 | 6 | const pets = ['cat', 'dog', 'bat']; 7 | 8 | console.log(pets.includes('cat')); 9 | // expected output: true 10 | 11 | console.log(pets.includes('at')); 12 | // expected output: false 13 | -------------------------------------------------------------------------------- /array/array-sort.js: -------------------------------------------------------------------------------- 1 | const months = ['March', 'Jan', 'Feb', 'Dec']; 2 | months.sort(); 3 | console.log(months); 4 | // expected output: Array ["Dec", "Feb", "Jan", "March"] 5 | 6 | const array1 = [1, 30, 4, 21, 100000]; 7 | array1.sort(); 8 | console.log(array1); 9 | // expected output: Array [1, 100000, 21, 30, 4] 10 | -------------------------------------------------------------------------------- /array/array-tolocalestring.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 'a', new Date('21 Dec 1997 14:12:00 UTC')]; 2 | const localeString = array1.toLocaleString('en', { timeZone: 'UTC' }); 3 | 4 | console.log(localeString); 5 | // expected output: "1,a,12/21/1997, 2:12:00 PM", 6 | // This assumes "en" locale and UTC timezone - your results may vary 7 | -------------------------------------------------------------------------------- /date/date-getutcday.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('August 19, 1975 23:15:30 GMT+11:00'); 2 | const date2 = new Date('August 19, 1975 23:15:30 GMT-11:00'); 3 | 4 | // Tuesday 5 | console.log(date1.getUTCDay()); 6 | // expected output: 2 7 | 8 | // Wednesday 9 | console.log(date2.getUTCDay()); 10 | // expected output: 3 11 | -------------------------------------------------------------------------------- /date/date-utc.js: -------------------------------------------------------------------------------- 1 | const utcDate1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5)); 2 | const utcDate2 = new Date(Date.UTC(0, 0, 0, 0, 0, 0)); 3 | 4 | console.log(utcDate1.toUTCString()); 5 | // expected output: Fri, 02 Feb 1996 03:04:05 GMT 6 | 7 | console.log(utcDate2.toUTCString()); 8 | // expected output: Sun, 31 Dec 1899 00:00:00 GMT 9 | -------------------------------------------------------------------------------- /expressions/expressions-destructuringassignment.js: -------------------------------------------------------------------------------- 1 | let a, b, rest; 2 | [a, b] = [10, 20]; 3 | 4 | console.log(a); 5 | // expected output: 10 6 | 7 | console.log(b); 8 | // expected output: 20 9 | 10 | [a, b, ...rest] = [10, 20, 30, 40, 50]; 11 | 12 | console.log(rest); 13 | // expected output: Array [30,40,50] 14 | -------------------------------------------------------------------------------- /expressions/expressions-groupingoperator.js: -------------------------------------------------------------------------------- 1 | console.log(1 + 2 * 3); // 1 + 6 2 | // expected output: 7 3 | 4 | console.log(1 + (2 * 3)); // 1 + 6 5 | // expected output: 7 6 | 7 | console.log((1 + 2) * 3); // 3 * 3 8 | // expected output: 9 9 | 10 | console.log(1 * 3 + 2 * 3); // 3 + 6 11 | // expected output: 9 12 | -------------------------------------------------------------------------------- /globalprops/globalprops-isnan.js: -------------------------------------------------------------------------------- 1 | function milliseconds(x) { 2 | if (isNaN(x)) { 3 | return 'Not a Number!'; 4 | } 5 | return x * 1000; 6 | } 7 | 8 | console.log(milliseconds('100F')); 9 | // expected output: "Not a Number!" 10 | 11 | console.log(milliseconds('0.0314E+2')); 12 | // expected output: 3140 13 | -------------------------------------------------------------------------------- /map/map-prototype-entries.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | 3 | map1.set('0', 'foo'); 4 | map1.set(1, 'bar'); 5 | 6 | const iterator1 = map1.entries(); 7 | 8 | console.log(iterator1.next().value); 9 | // expected output: ["0", "foo"] 10 | 11 | console.log(iterator1.next().value); 12 | // expected output: [1, "bar"] 13 | -------------------------------------------------------------------------------- /math/math-asinh.js: -------------------------------------------------------------------------------- 1 | console.log(Math.asinh(1)); 2 | // expected output: 0.881373587019543 3 | 4 | console.log(Math.asinh(0)); 5 | // expected output: 0 6 | 7 | console.log(Math.asinh(-1)); 8 | // expected output: -0.881373587019543 9 | 10 | console.log(Math.asinh(2)); 11 | // expected output: 1.4436354751788103 12 | -------------------------------------------------------------------------------- /math/math-exp.js: -------------------------------------------------------------------------------- 1 | console.log(Math.exp(0)); 2 | // expected output: 1 3 | 4 | console.log(Math.exp(1)); 5 | // expected output: 2.718281828459 (approximately) 6 | 7 | console.log(Math.exp(-1)); 8 | // expected output: 0.36787944117144233 9 | 10 | console.log(Math.exp(2)); 11 | // expected output: 7.38905609893065 12 | -------------------------------------------------------------------------------- /math/math-sqrt.js: -------------------------------------------------------------------------------- 1 | function calcHypotenuse(a, b) { 2 | return (Math.sqrt((a * a) + (b * b))); 3 | } 4 | 5 | console.log(calcHypotenuse(3, 4)); 6 | // expected output: 5 7 | 8 | console.log(calcHypotenuse(5, 12)); 9 | // expected output: 13 10 | 11 | console.log(calcHypotenuse(0, 0)); 12 | // expected output: 0 13 | -------------------------------------------------------------------------------- /object/object-getownpropertydescriptor.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1'); 6 | 7 | console.log(descriptor1.configurable); 8 | // expected output: true 9 | 10 | console.log(descriptor1.value); 11 | // expected output: 42 12 | -------------------------------------------------------------------------------- /reflect/reflect-ownkeys.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42, 3 | property2: 13 4 | }; 5 | 6 | const array1 = []; 7 | 8 | console.log(Reflect.ownKeys(object1)); 9 | // expected output: Array ["property1", "property2"] 10 | 11 | console.log(Reflect.ownKeys(array1)); 12 | // expected output: Array ["length"] 13 | -------------------------------------------------------------------------------- /set/set-prototype-@@iterator.js: -------------------------------------------------------------------------------- 1 | const set1 = new Set(); 2 | 3 | set1.add(42); 4 | set1.add('forty two'); 5 | 6 | const iterator1 = set1[Symbol.iterator](); 7 | 8 | console.log(iterator1.next().value); 9 | // expected output: 42 10 | 11 | console.log(iterator1.next().value); 12 | // expected output: "forty two" 13 | -------------------------------------------------------------------------------- /statement/statement-throw.js: -------------------------------------------------------------------------------- 1 | function getRectArea(width, height) { 2 | if (isNaN(width) || isNaN(height)) { 3 | throw 'Parameter is not a number!'; 4 | } 5 | } 6 | 7 | try { 8 | getRectArea(3, 'A'); 9 | } catch (e) { 10 | console.error(e); 11 | // expected output: "Parameter is not a number!" 12 | } 13 | -------------------------------------------------------------------------------- /string/string-matchall.js: -------------------------------------------------------------------------------- 1 | const regexp = /t(e)(st(\d?))/g; 2 | const str = 'test1test2'; 3 | 4 | const array = [...str.matchAll(regexp)]; 5 | 6 | console.log(array[0]); 7 | // expected output: Array ["test1", "e", "st1", "1"] 8 | 9 | console.log(array[1]); 10 | // expected output: Array ["test2", "e", "st2", "2"] 11 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-indexof.js: -------------------------------------------------------------------------------- 1 | const uint8 = new Uint8Array([10, 20, 30, 40, 50]); 2 | 3 | console.log(uint8.indexOf(50)); 4 | // expected output: 4 5 | 6 | // from position 3 7 | console.log(uint8.indexOf(20, 3)); 8 | // expected output: -1 9 | 10 | console.log(uint8.indexOf(51)); 11 | // expected output: -1 12 | -------------------------------------------------------------------------------- /MINI-DS-PROJECtS/memoization_project/test/util.js: -------------------------------------------------------------------------------- 1 | const catchStackOverflow = (fn, ...args) => { 2 | try { 3 | return fn(...args); 4 | } catch (err) { 5 | if (err instanceof RangeError) { 6 | throw new Error("Stack Overflow"); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = { 12 | catchStackOverflow, 13 | }; 14 | -------------------------------------------------------------------------------- /MINI-DS-PROJECtS/recursion_project/test/util.js: -------------------------------------------------------------------------------- 1 | const catchStackOverflow = (fn, ...args) => { 2 | try { 3 | return fn(...args); 4 | } catch (err) { 5 | if (err instanceof RangeError) { 6 | throw new Error("Stack Overflow"); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = { 12 | catchStackOverflow, 13 | }; 14 | -------------------------------------------------------------------------------- /SANDBOX/detect-capital.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/detect-capital/?tab=Description 2 | // Author : Bryan Guner 3 | 4 | /** 5 | * @param {string} word 6 | * @return {boolean} 7 | */ 8 | var detectCapitalUse = function (word) { 9 | let p = /^([a-z]+|[A-Z]+|[A-Z]{1}[a-z]+)$/; 10 | return p.test(word); 11 | }; 12 | -------------------------------------------------------------------------------- /expressions/expressions-classexpression.js: -------------------------------------------------------------------------------- 1 | const Rectangle = class { 2 | constructor(height, width) { 3 | this.height = height; 4 | this.width = width; 5 | } 6 | area() { 7 | return this.height * this.width; 8 | } 9 | }; 10 | 11 | console.log(new Rectangle(5, 8).area()); 12 | // expected output: 40 13 | -------------------------------------------------------------------------------- /intl/intl-collator-supportedlocalesof.js: -------------------------------------------------------------------------------- 1 | const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; 2 | const options1 = { localeMatcher: 'lookup' }; 3 | 4 | console.log(Intl.Collator.supportedLocalesOf(locales1, options1)); 5 | // expected output: Array ["id-u-co-pinyin", "de-ID"] 6 | // (Note: the exact output may be browser-dependent) 7 | -------------------------------------------------------------------------------- /map/map-prototype-@@iterator.js: -------------------------------------------------------------------------------- 1 | const map1 = new Map(); 2 | 3 | map1.set('0', 'foo'); 4 | map1.set(1, 'bar'); 5 | 6 | const iterator1 = map1[Symbol.iterator](); 7 | 8 | for (const item of iterator1) { 9 | console.log(item); 10 | } 11 | // expected output: Array ["0", "foo"] 12 | // expected output: Array [1, "bar"] 13 | -------------------------------------------------------------------------------- /object/object-seal.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | Object.seal(object1); 6 | object1.property1 = 33; 7 | console.log(object1.property1); 8 | // expected output: 33 9 | 10 | delete object1.property1; // cannot delete when sealed 11 | console.log(object1.property1); 12 | // expected output: 33 13 | -------------------------------------------------------------------------------- /string/string-raw.js: -------------------------------------------------------------------------------- 1 | 2 | // Create a variable that uses a Windows 3 | // path without escaping the backslashes: 4 | const filePath = String.raw`C:\Development\profile\aboutme.html`; 5 | 6 | console.log(`The file was uploaded from: ${filePath}`); 7 | // expected output: "The file was uploaded from: C:\Development\profile\aboutme.html" 8 | -------------------------------------------------------------------------------- /Complete-Projects/01_recursion_project/test/util.js: -------------------------------------------------------------------------------- 1 | const catchStackOverflow = (fn, ...args) => { 2 | try { 3 | return fn(...args); 4 | } catch (err) { 5 | if (err instanceof RangeError) { 6 | throw new Error("Stack Overflow"); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = { 12 | catchStackOverflow, 13 | }; 14 | -------------------------------------------------------------------------------- /Complete-Projects/02_memoization_project/test/util.js: -------------------------------------------------------------------------------- 1 | const catchStackOverflow = (fn, ...args) => { 2 | try { 3 | return fn(...args); 4 | } catch (err) { 5 | if (err instanceof RangeError) { 6 | throw new Error("Stack Overflow"); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = { 12 | catchStackOverflow, 13 | }; 14 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/intermediate-algorithm/11-spinal-tap-case.js: -------------------------------------------------------------------------------- 1 | function spinalCase(str) { 2 | str = str.replace(/([a-z])([A-Z])/g, "$1 $2"); //find patterns of aA, insert whitespace between! 3 | return (str = str.replace(/[\s\b_]/g, "-").toLowerCase()); 4 | } 5 | 6 | console.log(spinalCase("This_Is Spinal Tap thisIsSpinalTap")); 7 | -------------------------------------------------------------------------------- /array/array-reduce.js: -------------------------------------------------------------------------------- 1 | const array1 = [1, 2, 3, 4]; 2 | const reducer = (accumulator, currentValue) => accumulator + currentValue; 3 | 4 | // 1 + 2 + 3 + 4 5 | console.log(array1.reduce(reducer)); 6 | // expected output: 10 7 | 8 | // 5 + 1 + 2 + 3 + 4 9 | console.log(array1.reduce(reducer, 5)); 10 | // expected output: 15 11 | -------------------------------------------------------------------------------- /dataview/dataview-bytelength.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(16); 3 | 4 | const view1 = new DataView(buffer); 5 | const view2 = new DataView(buffer, 12, 4); //from byte 12 for the next 4 bytes 6 | 7 | console.log(view1.byteLength + view2.byteLength); // 16 + 4 8 | // expected output: 20 9 | -------------------------------------------------------------------------------- /date/date-getutcmonth.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00'); 2 | const date2 = new Date('December 31, 1975, 23:15:30 GMT-11:00'); 3 | 4 | // December 5 | console.log(date1.getUTCMonth()); 6 | // expected output: 11 7 | 8 | // January 9 | console.log(date2.getUTCMonth()); 10 | // expected output: 0 11 | -------------------------------------------------------------------------------- /expressions/expressions-addition.js: -------------------------------------------------------------------------------- 1 | console.log(2 + 2); 2 | // expected result: 4 3 | 4 | console.log(2 + true); 5 | // expected result: 3 6 | 7 | console.log('hello ' + 'everyone'); 8 | // expected result: "hello everyone" 9 | 10 | console.log(2001 + ': A Space Odyssey'); 11 | // expected result: "2001: A Space Odyssey" 12 | -------------------------------------------------------------------------------- /expressions/expressions-inoperator.js: -------------------------------------------------------------------------------- 1 | const car = { make: 'Honda', model: 'Accord', year: 1998 }; 2 | 3 | console.log('make' in car); 4 | // expected output: true 5 | 6 | delete car.make; 7 | if ('make' in car === false) { 8 | car.make = 'Suzuki'; 9 | } 10 | 11 | console.log(car.make); 12 | // expected output: "Suzuki" 13 | -------------------------------------------------------------------------------- /globalprops/globalprops-parseint.js: -------------------------------------------------------------------------------- 1 | function roughScale(x, base) { 2 | const parsed = parseInt(x, base); 3 | if (isNaN(parsed)) { return 0; } 4 | return parsed * 100; 5 | } 6 | 7 | console.log(roughScale(' 0xF', 16)); 8 | // expected output: 1500 9 | 10 | console.log(roughScale('321', 2)); 11 | // expected output: 0 12 | -------------------------------------------------------------------------------- /intl/intl-collator-prototype-resolvedoptions.js: -------------------------------------------------------------------------------- 1 | const numberDe = new Intl.NumberFormat('de-DE'); 2 | const numberAr = new Intl.NumberFormat('ar'); 3 | 4 | console.log(numberDe.resolvedOptions().numberingSystem); 5 | // expected output: "latn" 6 | 7 | console.log(numberAr.resolvedOptions().numberingSystem); 8 | // expected output: "arab" 9 | -------------------------------------------------------------------------------- /intl/intl-numberformat-supportedlocalesof.js: -------------------------------------------------------------------------------- 1 | const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; 2 | const options1 = { localeMatcher: 'lookup' }; 3 | 4 | console.log(Intl.NumberFormat.supportedLocalesOf(locales1, options1)); 5 | // expected output: Array ["id-u-co-pinyin", "de-ID"] 6 | // (Note: the exact output may be browser-dependent) 7 | -------------------------------------------------------------------------------- /math/math-acos.js: -------------------------------------------------------------------------------- 1 | // Calculates angle of a right-angle triangle in radians 2 | function calcAngle(adjacent, hypotenuse) { 3 | return Math.acos(adjacent / hypotenuse); 4 | } 5 | 6 | console.log(calcAngle(8, 10)); 7 | // expected output: 0.6435011087932843 8 | 9 | console.log(calcAngle(5, 3)); 10 | // expected output: NaN 11 | -------------------------------------------------------------------------------- /math/math-asin.js: -------------------------------------------------------------------------------- 1 | // Calculates angle of a right-angle triangle in radians 2 | function calcAngle(opposite, hypotenuse) { 3 | return Math.asin(opposite / hypotenuse); 4 | } 5 | 6 | console.log(calcAngle(6, 10)); 7 | // expected output: 0.6435011087932844 8 | 9 | console.log(calcAngle(5, 3)); 10 | // expected output: NaN 11 | -------------------------------------------------------------------------------- /math/math-atan2.js: -------------------------------------------------------------------------------- 1 | function calcAngleDegrees(x, y) { 2 | return Math.atan2(y, x) * 180 / Math.PI; 3 | } 4 | 5 | console.log(calcAngleDegrees(5, 5)); 6 | //expected output: 45 7 | 8 | console.log(calcAngleDegrees(10, 10)); 9 | //expected output: 45 10 | 11 | console.log(calcAngleDegrees(0, 10)); 12 | //expected output: 90 13 | -------------------------------------------------------------------------------- /math/math-clz32.js: -------------------------------------------------------------------------------- 1 | // 00000000000000000000000000000001 2 | console.log(Math.clz32(1)); 3 | // expected output: 31 4 | 5 | // 00000000000000000000000000000100 6 | console.log(Math.clz32(4)); 7 | // expected output: 29 8 | 9 | // 00000000000000000000001111101000 10 | console.log(Math.clz32(1000)); 11 | // expected output: 22 12 | -------------------------------------------------------------------------------- /math/math-pow.js: -------------------------------------------------------------------------------- 1 | console.log(Math.pow(7, 3)); 2 | // expected output: 343 3 | 4 | console.log(Math.pow(4, 0.5)); 5 | // expected output: 2 6 | 7 | console.log(Math.pow(7, -2)); 8 | // expected output: 0.02040816326530612 9 | // (1/49) 10 | 11 | console.log(Math.pow(-7, 0.5)); 12 | // expected output: NaN 13 | -------------------------------------------------------------------------------- /number/number-isnan.js: -------------------------------------------------------------------------------- 1 | function typeOfNaN(x) { 2 | if (Number.isNaN(x)) { 3 | return 'Number NaN'; 4 | } 5 | if (isNaN(x)) { 6 | return 'NaN'; 7 | } 8 | } 9 | 10 | console.log(typeOfNaN('100F')); 11 | // expected output: "NaN" 12 | 13 | console.log(typeOfNaN(NaN)); 14 | // expected output: "Number NaN" 15 | -------------------------------------------------------------------------------- /number/number-toexponential.js: -------------------------------------------------------------------------------- 1 | function expo(x, f) { 2 | return Number.parseFloat(x).toExponential(f); 3 | } 4 | 5 | console.log(expo(123456, 2)); 6 | // expected output: "1.23e+5" 7 | 8 | console.log(expo('123456')); 9 | // expected output: "1.23456e+5" 10 | 11 | console.log(expo('oink')); 12 | // expected output: "NaN" 13 | -------------------------------------------------------------------------------- /object/object-assign.js: -------------------------------------------------------------------------------- 1 | const target = { a: 1, b: 2 }; 2 | const source = { b: 4, c: 5 }; 3 | 4 | const returnedTarget = Object.assign(target, source); 5 | 6 | console.log(target); 7 | // expected output: Object { a: 1, b: 4, c: 5 } 8 | 9 | console.log(returnedTarget); 10 | // expected output: Object { a: 1, b: 4, c: 5 } 11 | -------------------------------------------------------------------------------- /object/object-getownpropertydescriptors.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | const descriptors1 = Object.getOwnPropertyDescriptors(object1); 6 | 7 | console.log(descriptors1.property1.writable); 8 | // expected output: true 9 | 10 | console.log(descriptors1.property1.value); 11 | // expected output: 42 12 | -------------------------------------------------------------------------------- /object/object-getownpropertysymbols.js: -------------------------------------------------------------------------------- 1 | const object1 = {}; 2 | const a = Symbol('a'); 3 | const b = Symbol.for('b'); 4 | 5 | object1[a] = 'localSymbol'; 6 | object1[b] = 'globalSymbol'; 7 | 8 | const objectSymbols = Object.getOwnPropertySymbols(object1); 9 | 10 | console.log(objectSymbols.length); 11 | // expected output: 2 12 | -------------------------------------------------------------------------------- /object/object-prototype-tolocalestring.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); 2 | 3 | console.log(date1.toLocaleString('ar-EG')); 4 | // expected output: "٢٠‏/١٢‏/٢٠١٢ ٤:٠٠:٠٠ ص" 5 | 6 | const number1 = 123456.789; 7 | 8 | console.log(number1.toLocaleString('de-DE')); 9 | // expected output: "123.456,789" 10 | -------------------------------------------------------------------------------- /statement/statement-const.js: -------------------------------------------------------------------------------- 1 | const number = 42; 2 | 3 | try { 4 | number = 99; 5 | } catch (err) { 6 | console.log(err); 7 | // expected output: TypeError: invalid assignment to const `number' 8 | // Note - error messages will vary depending on browser 9 | } 10 | 11 | console.log(number); 12 | // expected output: 42 13 | -------------------------------------------------------------------------------- /ALGO/UNSORTED/prime-number.js: -------------------------------------------------------------------------------- 1 | export default (n) => { 2 | if (n === 2) { 3 | return true; 4 | } 5 | if (n < 2 || !(n & 1)) { 6 | return false; 7 | } 8 | 9 | for (let i = 3, l = Math.floor(n ** 0.5); i <= l; i += 2) { 10 | if (n % i === 0) { 11 | return false; 12 | } 13 | } 14 | 15 | return true; 16 | }; 17 | -------------------------------------------------------------------------------- /ALGO/__PYTHON/prime-number.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | 3 | def is_prime(n): 4 | if n <= 1: 5 | return False 6 | elif n == 2: 7 | return True 8 | elif n % 2 == 0: 9 | return False 10 | for i in xrange(3, int(sqrt(n))+1, 2): 11 | if n % i == 0: 12 | return False 13 | return True 14 | -------------------------------------------------------------------------------- /ALGO/bmi.py: -------------------------------------------------------------------------------- 1 | #The program calculates your BMI and returns the result 2 | 3 | a= float(input("Type your weight \n")) 4 | b= float(input("Type your height \n")) 5 | bmi = a/b**2 6 | print(bmi) 7 | if (bmi <=5): 8 | print ("under weight") 9 | if (bmi ==6)and (bmi<=24): 10 | print ("Normal weight") 11 | if (bmi >=25): 12 | print ("obesity") -------------------------------------------------------------------------------- /ALGO/longest-common-prefix/Readme.md: -------------------------------------------------------------------------------- 1 | # Longest Common Prefix 2 | 3 | Given a String array, find the longest common prefix. 4 | 5 | ## Example 6 | 7 | ``` 8 | f(['rocket', 'rockstar', 'rockbottom', 'rock', 'rollingstone'] // 'ro' 9 | f(['shuffle', 'shuttle', 'shut'] // 'shu' 10 | ``` 11 | 12 | ## Source 13 | 14 | Personal Phone Interview 15 | -------------------------------------------------------------------------------- /ALGO/search-unknown-length-array/Readme.md: -------------------------------------------------------------------------------- 1 | # Search Unknown Length Array 2 | 3 | Given a sorted array of unknown length and a number to search for, return the index of the number in the array. Accessing an element out of bounds throws exception. If the number occurs multiple times, return the index of any occurrence. If it isn't present, return -1. 4 | -------------------------------------------------------------------------------- /Arrays/basic-examples/problems/number-fun.js: -------------------------------------------------------------------------------- 1 | function returnsThree() { 2 | return 3; 3 | } 4 | 5 | function reciprocal(n) { 6 | if (n < 1 || n > 1000000) { 7 | throw new TypeError("Number out of range from 1 to 1000000"); 8 | } 9 | return 1 / n; 10 | } 11 | 12 | module.exports = { 13 | returnsThree, 14 | reciprocal, 15 | }; 16 | -------------------------------------------------------------------------------- /SANDBOX/arranging-coins.js: -------------------------------------------------------------------------------- 1 | // Source : https://leetcode.com/problems/arranging-coins/ 2 | // Author : Bryan Guner 3 | 4 | "use strict"; 5 | 6 | /** 7 | * @param {number} n 8 | * @return {number} 9 | */ 10 | var arrangeCoins = function (n) { 11 | let ans = Math.sqrt(1 + 8 * n) - 1; 12 | ans /= 2; 13 | 14 | return ~~ans; 15 | }; 16 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/intermediate-algorithm/08-boo-hoo-booleans.js: -------------------------------------------------------------------------------- 1 | function booWho(bool) { 2 | // What is the new fad diet for ghost developers? The Boolean. -- actually pretty funny 3 | if (typeof bool === "boolean") { 4 | return true; 5 | } else { 6 | return false; 7 | } 8 | } 9 | 10 | console.log(booWho(true)); 11 | -------------------------------------------------------------------------------- /_Extra-Practice/free-code-camp/nodejs/http-client.js: -------------------------------------------------------------------------------- 1 | const http = require("http"); 2 | 3 | http 4 | .get(process.argv[2], (res) => { 5 | res.on("error", console.error); 6 | res 7 | .on("data", (data) => { 8 | console.log(data); 9 | }) 10 | .setEncoding("utf8"); 11 | }) 12 | .on("error", console.error); 13 | -------------------------------------------------------------------------------- /array/array-filter.js: -------------------------------------------------------------------------------- 1 | const words = [ 2 | 'spray', 3 | 'limit', 4 | 'elite', 5 | 'exuberant', 6 | 'destruction', 7 | 'present', 8 | ]; 9 | 10 | const result = words.filter((word) => word.length > 6); 11 | 12 | console.log(result); 13 | // expected output: Array ["exuberant", "destruction", "present"] 14 | -------------------------------------------------------------------------------- /atomics/atomics-store.js: -------------------------------------------------------------------------------- 1 | // create a SharedArrayBuffer with a size in bytes 2 | const buffer = new SharedArrayBuffer(16); 3 | const uint8 = new Uint8Array(buffer); 4 | uint8[0] = 5; 5 | 6 | console.log(Atomics.store(uint8, 0, 2)); 7 | // expected output: 2 8 | 9 | console.log(Atomics.load(uint8, 0)); 10 | // expected output: 2 11 | -------------------------------------------------------------------------------- /intl/intl-datetimeformat-supportedlocalesof.js: -------------------------------------------------------------------------------- 1 | const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; 2 | const options1 = { localeMatcher: 'lookup' }; 3 | 4 | console.log(Intl.DateTimeFormat.supportedLocalesOf(locales1, options1)); 5 | // expected output: Array ["id-u-co-pinyin", "de-ID"] 6 | // (Note: the exact output may be browser-dependent) 7 | -------------------------------------------------------------------------------- /number/number-max-safe-integer.js: -------------------------------------------------------------------------------- 1 | const x = Number.MAX_SAFE_INTEGER + 1; 2 | const y = Number.MAX_SAFE_INTEGER + 2; 3 | 4 | console.log(Number.MAX_SAFE_INTEGER); 5 | // expected output: 9007199254740991 6 | 7 | console.log(x); 8 | // expected output: 9007199254740992 9 | 10 | console.log(x === y); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /number/number-min-safe-integer.js: -------------------------------------------------------------------------------- 1 | const x = Number.MIN_SAFE_INTEGER - 1; 2 | const y = Number.MIN_SAFE_INTEGER - 2; 3 | 4 | console.log(Number.MIN_SAFE_INTEGER); 5 | // expected output: -9007199254740991 6 | 7 | console.log(x); 8 | // expected output: -9007199254740992 9 | 10 | console.log(x === y); 11 | // expected output: true 12 | -------------------------------------------------------------------------------- /number/number-tofixed.js: -------------------------------------------------------------------------------- 1 | function financial(x) { 2 | return Number.parseFloat(x).toFixed(2); 3 | } 4 | 5 | console.log(financial(123.456)); 6 | // expected output: "123.46" 7 | 8 | console.log(financial(0.004)); 9 | // expected output: "0.00" 10 | 11 | console.log(financial('1.23e+5')); 12 | // expected output: "123000.00" 13 | -------------------------------------------------------------------------------- /number/number-toprecision.js: -------------------------------------------------------------------------------- 1 | function precise(x) { 2 | return Number.parseFloat(x).toPrecision(4); 3 | } 4 | 5 | console.log(precise(123.456)); 6 | // expected output: "123.5" 7 | 8 | console.log(precise(0.004)); 9 | // expected output: "0.004000" 10 | 11 | console.log(precise('1.23e+5')); 12 | // expected output: "1.230e+5" 13 | -------------------------------------------------------------------------------- /reflect/reflect-has.js: -------------------------------------------------------------------------------- 1 | const object1 = { 2 | property1: 42 3 | }; 4 | 5 | console.log(Reflect.has(object1, 'property1')); 6 | // expected output: true 7 | 8 | console.log(Reflect.has(object1, 'property2')); 9 | // expected output: false 10 | 11 | console.log(Reflect.has(object1, 'toString')); 12 | // expected output: true 13 | -------------------------------------------------------------------------------- /regexp/regexp-prototype-@@search.js: -------------------------------------------------------------------------------- 1 | class RegExp1 extends RegExp { 2 | constructor(str) { 3 | super(str); 4 | this.pattern = str; 5 | } 6 | [Symbol.search](str) { 7 | return str.indexOf(this.pattern); 8 | } 9 | } 10 | 11 | console.log('table football'.search(new RegExp1('foo'))); 12 | // expected output: 6 13 | -------------------------------------------------------------------------------- /set/set-prototype-foreach.js: -------------------------------------------------------------------------------- 1 | function logSetElements(value1, value2, set) { 2 | console.log(`s[${value1}] = ${value2}`); 3 | } 4 | 5 | new Set(['foo', 'bar', undefined]).forEach(logSetElements); 6 | 7 | // expected output: "s[foo] = foo" 8 | // expected output: "s[bar] = bar" 9 | // expected output: "s[undefined] = undefined" 10 | -------------------------------------------------------------------------------- /ALGO/permutation.py: -------------------------------------------------------------------------------- 1 | # Calculating permutation 2 | 3 | n = int(input("please enter the value of n: ")) 4 | r = int(input("Please enter the value of r: ")) 5 | 6 | 7 | a = (n - r) 8 | x = 1 9 | 10 | for n in range(n, 0, -1): 11 | x *= n 12 | 13 | y = 1 14 | for a in range(a, 0, -1): 15 | y *= a 16 | 17 | nPr = x/y 18 | print(nPr) 19 | -------------------------------------------------------------------------------- /ALGO/remove-duplicates-from-string/remove-duplicates-from-string.js: -------------------------------------------------------------------------------- 1 | module.exports = (string) => { 2 | let output = ""; 3 | const hash = {}; 4 | 5 | for (let i = 0; i < string.length; i++) { 6 | if (!hash[string[i]]) { 7 | output += string[i]; 8 | } 9 | hash[string[i]] = true; 10 | } 11 | 12 | return output; 13 | }; 14 | -------------------------------------------------------------------------------- /ALGO/reverse-a-string.js: -------------------------------------------------------------------------------- 1 | // Reverse a String 2 | 3 | /* 4 | Reverse the provided string. 5 | 6 | You may need to turn the string into an array before you can reverse it. 7 | 8 | Your result must be a string. 9 | */ 10 | 11 | function reverseString(str) { 12 | return str.split('').reverse().join(''); 13 | } 14 | 15 | reverseString('hello'); 16 | -------------------------------------------------------------------------------- /ALGO/spinal-tap-case.js: -------------------------------------------------------------------------------- 1 | // Spinal Tap Case 2 | 3 | /* 4 | Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes. 5 | */ 6 | 7 | function spinalCase(str) { 8 | str = str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase().replace(/[\s_]/g, '-'); 9 | return str; 10 | } 11 | 12 | spinalCase('This Is Spinal Tap'); 13 | -------------------------------------------------------------------------------- /Fifo-Lifo/Queue/qfroms/stack.js: -------------------------------------------------------------------------------- 1 | class Stack { 2 | constructor() { 3 | this.data = []; 4 | } 5 | 6 | push(record) { 7 | this.data.push(record); 8 | } 9 | 10 | pop() { 11 | return this.data.pop(); 12 | } 13 | 14 | peek() { 15 | return this.data[this.data.length - 1]; 16 | } 17 | } 18 | 19 | module.exports = Stack; 20 | -------------------------------------------------------------------------------- /array/array-indexof.js: -------------------------------------------------------------------------------- 1 | const beasts = ['ant', 'bison', 'camel', 'duck', 'bison']; 2 | 3 | console.log(beasts.indexOf('bison')); 4 | // expected output: 1 5 | 6 | // start from index 2 7 | console.log(beasts.indexOf('bison', 2)); 8 | // expected output: 4 9 | 10 | console.log(beasts.indexOf('giraffe')); 11 | // expected output: -1 12 | -------------------------------------------------------------------------------- /expressions/expressions-conditionaloperators.js: -------------------------------------------------------------------------------- 1 | function getFee(isMember) { 2 | return (isMember ? '$2.00' : '$10.00'); 3 | } 4 | 5 | console.log(getFee(true)); 6 | // expected output: "$2.00" 7 | 8 | console.log(getFee(false)); 9 | // expected output: "$10.00" 10 | 11 | console.log(getFee(null)); 12 | // expected output: "$10.00" 13 | -------------------------------------------------------------------------------- /globalprops/globalprops-isfinite.js: -------------------------------------------------------------------------------- 1 | function div(x) { 2 | if (isFinite(1000 / x)) { 3 | return 'Number is NOT Infinity.'; 4 | } 5 | return 'Number is Infinity!'; 6 | } 7 | 8 | console.log(div(0)); 9 | // expected output: "Number is Infinity!"" 10 | 11 | console.log(div(1)); 12 | // expected output: "Number is NOT Infinity." 13 | -------------------------------------------------------------------------------- /math/math-atan.js: -------------------------------------------------------------------------------- 1 | // Calculates angle of a right-angle triangle in radians 2 | function calcAngle(opposite, adjacent) { 3 | return Math.atan(opposite / adjacent); 4 | } 5 | 6 | console.log(calcAngle(8, 10)); 7 | // expected output: 0.6747409422235527 8 | 9 | console.log(calcAngle(5, 3)); 10 | // expected output: 1.0303768265243125 11 | -------------------------------------------------------------------------------- /math/math-random.js: -------------------------------------------------------------------------------- 1 | function getRandomInt(max) { 2 | return Math.floor(Math.random() * Math.floor(max)); 3 | } 4 | 5 | console.log(getRandomInt(3)); 6 | // expected output: 0, 1 or 2 7 | 8 | console.log(getRandomInt(1)); 9 | // expected output: 0 10 | 11 | console.log(Math.random()); 12 | // expected output: a number from 0 to <1 13 | -------------------------------------------------------------------------------- /number/number-tolocalestring.js: -------------------------------------------------------------------------------- 1 | function eArabic(x){ 2 | return x.toLocaleString('ar-EG'); 3 | } 4 | 5 | console.log(eArabic(123456.789)); 6 | // expected output: "١٢٣٬٤٥٦٫٧٨٩" 7 | 8 | console.log(eArabic('123456.789')); 9 | // expected output: "123456.789" 10 | 11 | console.log(eArabic(NaN)); 12 | // expected output: "ليس رقم" 13 | -------------------------------------------------------------------------------- /regexp/regexp-prototype-source.js: -------------------------------------------------------------------------------- 1 | const regex1 = /fooBar/ig; 2 | 3 | console.log(regex1.source); 4 | // expected output: "fooBar" 5 | 6 | console.log(new RegExp().source); 7 | // expected output: "(?:)" 8 | 9 | console.log(new RegExp('\n').source === '\\n'); 10 | // expected output: true (starting with ES5) 11 | // (due to escaping) 12 | -------------------------------------------------------------------------------- /ALGO/typedarray/typedarray-set.js: -------------------------------------------------------------------------------- 1 | // create an ArrayBuffer with a size in bytes 2 | const buffer = new ArrayBuffer(8); 3 | const uint8 = new Uint8Array(buffer); 4 | 5 | // Copy the values into the array starting at index 3 6 | uint8.set([1, 2, 3], 3); 7 | 8 | console.log(uint8); 9 | // expected output: Uint8Array [0, 0, 0, 1, 2, 3, 0, 0] 10 | -------------------------------------------------------------------------------- /ALGO/weakmap/weakmap-prototype-set.js: -------------------------------------------------------------------------------- 1 | const weakmap1 = new WeakMap(); 2 | const object1 = {}; 3 | const object2 = {}; 4 | 5 | weakmap1.set(object1, 'foo'); 6 | weakmap1.set(object2, 'bar'); 7 | 8 | console.log(weakmap1.get(object1)); 9 | //expected output: "foo" 10 | 11 | console.log(weakmap1.get(object2)); 12 | //expected output: "bar" 13 | -------------------------------------------------------------------------------- /date/date-getutcminutes.js: -------------------------------------------------------------------------------- 1 | const date1 = new Date('1 January 2000 03:15:30 GMT+07:00'); 2 | const date2 = new Date('1 January 2000 03:15:30 GMT+03:30'); 3 | 4 | console.log(date1.getUTCMinutes()); // 31 Dec 1999 20:15:30 GMT 5 | // expected output: 15 6 | 7 | console.log(date2.getUTCMinutes()); // 31 Dec 1999 23:45:30 GMT 8 | // expected output: 45 9 | --------------------------------------------------------------------------------