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
function matrix(n) { | |
let result = []; | |
for(let i = 0; i < n; i++) { | |
result.push([]); | |
} | |
let counter = 1; | |
let startColun = 0; |
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
function sequence(seq) { | |
var bad = 0 | |
for(var i=1;i<seq.length;i++) { | |
if(seq[i]<=seq[i-1]) { | |
bad++ | |
if(bad>1) { | |
return false | |
} | |
if(seq[i]<=seq[i-2]&&seq[i+1]<=seq[i-1]) { | |
return false |
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
// Show the complete implementation | |
// of the stack class | |
function Stack() { | |
this.dataStore = []; | |
this.top = 0; | |
this.push = push; | |
this.pop = pop; | |
this.peek = peek; | |
this.clear = clear; |
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
/* | |
let a = []; | |
const bubbleSort = (arr) => { | |
let newArr = arr.sort((a,b) => a - b); | |
for(let i = newArr[0]; i <= newArr[newArr.length - 1]; i++){ | |
a.push(i); | |
} | |
return a.length - newArr.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 prepareTea = () => "greenTea"; | |
const getTea = (numOfCups) =>{ | |
const teaCups = []; | |
for(let cups = 1; cups < numOfCups; cups++){ | |
const teaCup = prepareTea(); | |
teaCups.push(teaCup); |
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
function truncateString(str, num) { | |
// Clear out that junk in your trunk | |
return str.length > num ? str.slice(0, num).concat('...') : str; | |
} | |
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and".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
function confirmEnding(str, target) { | |
// "Never give up and good luck will find you." | |
// -- Falcor | |
if(str.slice(str.length-target.length) === target){ | |
return true; | |
} | |
else | |
return false; |
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
function confirmEnding(str, target) { | |
// "Never give up and good luck will find you." | |
// -- Falcor | |
if(str.slice(str.length-target.length) === target){ | |
return true; | |
} | |
else | |
return false; |
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
function compareTriplets(a,b){ | |
let alice = 0, bob = 0; | |
let result = []; | |
for(var i = 0; i < 3; i++){ | |
if(a[i] > b[i]){ | |
alice++; | |
} | |
else if(a[i] < b[i]){ | |
bob++; | |
} |
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
class Book { | |
constructor(author){ | |
this._author = author; | |
} | |
//getter | |
get writer(){ | |
return this._author; | |
} |