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
// Heap's algorithm (iterative version, recursive version took waaaay longer) | |
// https://en.wikipedia.org/wiki/Heap%27s_algorithm | |
// Even though I kinda understand the algorithm, | |
// *after* reading about it and converting it to JS | |
// I can't pretend that I came up with this solution on my own. | |
const permutate = str => { | |
const lengthOfString = str.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
//todo | |
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]; | |
var daysCopy = days; | |
days.push("Saturday", "Sunday"); | |
daysCopy[0] = "Lundi"; | |
console.log(days); | |
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] |
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
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]; | |
var daysCopy = days.slice(); | |
days.push("Saturday", "Sunday"); | |
daysCopy[0] = "Lundi"; | |
console.log(days); | |
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] | |
console.log(daysCopy); |
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
var array = [1, 2, [3, 4], [5, 6, [7, 8], 9], 10]; | |
var string = array.toString(); | |
console.log(string); | |
// 1,2,3,4,5,6,7,8,9,10 |
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
var array = ["Monday", "Tuesday", "Wednesday"]; | |
array.name = "Paul"; | |
array.age = 35; | |
console.log(array); | |
// ["Monday", "Tuesday", "Wednesday", name: "Paul", age: 35] | |
console.log(array.length); | |
// 3 |
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
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; | |
days.forEach( (element, index) => { | |
console.log(element, index); | |
}) |
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
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Saturday", "Sunday"]; | |
if( days.indexOf("Wednesday") > -1 ){ | |
console.log("contains Wednesday!"); | |
} | |
// same as | |
var containsWednesday = days.some(function(element){ | |
return element === "Wednesday"; | |
}); |
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
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Saturday", "Sunday"]; | |
var removed = days.splice(4, 2, "Friday"); | |
console.log(days); | |
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] | |
console.log(removed); | |
// [Saturday, Sunday] |
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
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; | |
var copy = days.slice(); | |
var weekend = days.slice(5); | |
var alsoWeekend = days.slice(-2); | |
var weekdays = days.slice(0, 5); | |
var alsoWeekdays = days.slice(0, -2); | |
console.log(copy); | |
// ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] |
NewerOlder