Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d70595e

Browse files
Merge branch 'master' into add-trapping-water
2 parents 826d75b + d272b1e commit d70595e

File tree

130 files changed

+10268
-1047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+10268
-1047
lines changed

‎.prettierrc‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"endOfLine": "lf",
5+
"insertPragma": false,
6+
"printWidth": 80,
7+
"proseWrap": "preserve",
8+
"quoteProps": "as-needed",
9+
"requirePragma": false,
10+
"semi": false,
11+
"singleQuote": true,
12+
"tabWidth": 2,
13+
"trailingComma": "none",
14+
"useTabs": false
15+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎Ciphers/ROT13.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Transcipher a ROT13 cipher
3+
* @param {String} text - string to be encrypted
4+
* @return {String} - decrypted string
5+
*/
6+
const transcipher = (text) => {
7+
const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
8+
const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
9+
const index = x => originalCharacterList.indexOf(x)
10+
const replace = x => index(x) > -1 ? toBeMappedCharaterList[index(x)] : x
11+
return text.split('').map(replace).join('')
12+
}
13+
14+
(() => {
15+
const messageToBeEncrypted = 'The quick brown fox jumps over the lazy dog'
16+
console.log(`Original Text = "${messageToBeEncrypted}"`)
17+
const rot13CipheredText = transcipher(messageToBeEncrypted)
18+
console.log(`Ciphered Text = "${rot13CipheredText}"`)
19+
const rot13DecipheredText = transcipher(rot13CipheredText)
20+
console.log(`Deciphered Text = "${rot13DecipheredText}"`)
21+
})()

‎Conversions/BinaryToDecimal.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
functionbinaryToDeicmal(binaryNumber) {
1+
constbinaryToDecimal=(binaryString)=> {
22
let decimalNumber = 0
3-
const binaryDigits = binaryNumber.split('').reverse() // Splits the binary number into reversed single digits
3+
const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits
44
binaryDigits.forEach((binaryDigit, index) => {
55
decimalNumber += binaryDigit * (Math.pow(2, index)) // Summation of all the decimal converted digits
66
})
7-
console.log(`Decimal of ${binaryNumber} is ${decimalNumber}`)
7+
console.log(`Decimal of ${binaryString} is ${decimalNumber}`)
8+
return decimalNumber
89
}
910

10-
binaryToDeicmal('111001')
11-
binaryToDeicmal('101')
11+
(() => {
12+
binaryToDecimal('111001')
13+
binaryToDecimal('101')
14+
})()

‎Conversions/HexToRGB.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function hexStringToRGB (hexString) {
2-
var r = (hexString.substring(1,3)).toUpperCase()
3-
var g = hexString.substring(3,5).toUpperCase()
4-
var b = hexString.substring(5,7).toUpperCase()
2+
var r = hexString.substring(0,2)
3+
var g = hexString.substring(2,4)
4+
var b = hexString.substring(4,6)
55

66
r = parseInt(r, 16)
77
g = parseInt(g, 16)
@@ -11,4 +11,4 @@ function hexStringToRGB (hexString) {
1111
return obj
1212
}
1313

14-
console.log(hexStringToRGB('javascript rock !!'))
14+
console.log(hexStringToRGB('ffffff'))

‎Conversions/RGBToHex.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function RGBToHex (r, g, b) {
2+
if (
3+
typeof r !== 'number' ||
4+
typeof g !== 'number' ||
5+
typeof b !== 'number'
6+
) {
7+
throw new TypeError('argument is not a Number')
8+
}
9+
10+
const toHex = n => (n || '0').toString(16).padStart(2, '0')
11+
12+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
13+
}
14+
15+
console.log(RGBToHex(255, 255, 255) === '#ffffff')
16+
console.log(RGBToHex(255, 99, 71) === '#ff6347')

‎DIRECTORY.md‎

Lines changed: 112 additions & 8 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* A LinkedList based solution for Detect a Cycle in a list
3+
* https://en.wikipedia.org/wiki/Cycle_detection
4+
*/
5+
6+
function main () {
7+
/*
8+
Problem Statement:
9+
Given head, the head of a linked list, determine if the linked list has a cycle in it.
10+
11+
Note:
12+
* While Solving the problem in given link below, don't use main() function.
13+
* Just use only the code inside main() function.
14+
* The purpose of using main() function here is to aviod global variables.
15+
16+
Link for the Problem: https://leetcode.com/problems/linked-list-cycle/
17+
*/
18+
const head = '' // Reference to head is given in the problem. So please ignore this line
19+
let fast = head
20+
let slow = head
21+
22+
while (fast != null && fast.next != null && slow != null) {
23+
fast = fast.next.next
24+
slow = slow.next
25+
if (fast === slow) {
26+
return true
27+
}
28+
}
29+
return false
30+
}
31+
32+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /