This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reverse a string using stack data structure | |
const reverse = s => { | |
let stack = []; | |
let reversed = ''; | |
// push all characters of string to stack | |
for (var i = 0; i < s.length; i++) { | |
stack.push(s[i]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const xl = require('excel4node'); | |
const app = express(); | |
const makeReport = (request, response) => { | |
const wb = new xl.Workbook(); | |
const ws = wb.addWorksheet('Ödenmiş Mesai Raporu'); | |
// Create a reusable style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LinkedList = () => { | |
let length = 0; | |
let headNode = null; | |
let Node = (element) => ({ | |
element, | |
next: null, | |
}); | |
let size = () => length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sum = ([x, ...xs]) => ( | |
xs.length === 0 | |
? x | |
: x + sum(xs) | |
); | |
console.log(sum([2, 4, 6])); // 12 | |
const count = ([x, ...xs]) => ( | |
xs.length === 0 | |
? 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineReducers = reducers => (state = {}, action) => | |
Object.keys(reducers).reduce((acc, key) => ({ | |
...acc, | |
[key]: reducers[key](state[key], action) | |
}), {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// isValid -> Date -> Bool | |
const isValidDate = d => d instanceof Date && !isNaN(d.getTime()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// it works only with strings | |
const isPalindrome = ([head, ...tail]) => { | |
if (tail.length === 0) return true | |
if (head !== tail[tail.length - 1]) return false | |
return isPalindrome(tail.slice(0, tail.length - 1)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sumUntil = (a, target) => | |
[...a].reduce((acc, n, _, arr) => n === target ? (arr.length = 0, acc) : acc + n) | |
sumUntil([1, 2, 3, 36, 4], 36) // 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
'Ankara', | |
'Milano', | |
'Berlin' | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const Countries = [ | |
'Turkey', 'Italy', 'Germany' | |
] | |
const app = http.createServer((req, res) => { | |
res.setHeader("Access-Control-Allow-Origin", "*"); | |
res.writeHead(200, { 'Content-Type': 'application/json' }) | |
res.end(JSON.stringify(Countries)); |