Skip to content

Instantly share code, notes, and snippets.

View Jagathishrex's full-sized avatar
🎯
Focusing

Jagathishrex

🎯
Focusing
View GitHub Profile
var array = [11,2,3,4,5];
var isGreaterThanTen = array.every(function(item, index, array) {
let isLastIndex = index === array.length - 1;
if(isLastIndex === false) {
array[index + 1] += 10;
}
return item > 10;
});
var arr = [false, false, true, true];
var hasTrue = arr.some((item, index, arr) => {
arr.pop();
return item;
});
console.log(hasTrue); // false
var arr = [false, false, true, true];
var hasTrue = arr.some((item, index, arr) => {
arr.pop();
return item;
});
console.log(hasTrue); // false
var arr = [false,false];
let hasTrue = arr.some((item, index, arr) => {
arr.push(true);
return item;
});
console.log(hasTrue); // false
var array = [false, false,false];
var hasTrue = array.some( function(item, index, array) {
let isLastIndex = index === array.length - 1;
if(isLastIndex === false) {
array[index + 1] = true;
}
return item;
});
class Stack {
constructor(){
this.data = [];
this.top = 0;
}
push(element) {
this.data[this.top] = element;
this.top = this.top + 1;
}
length() {
class Queue {
constructor(){
this.data = [];
this.rear = 0;
this.size = 10;
}
enqueue(element) {
var obj = {one : 1, two : 2};
var copiedObj = {...obj};
copiedObj.one = 3;
console.log(copiedObj.one); // 3
console.log(obj.one); // 1
function copy(sourceObj) {
let targetObj = {};
let keys = Object.keys(sourceObj);
for (let i = 0, len = keys.length; i < len; i++) {
let key = keys[i];
targetObj[key] = sourceObj[key];
}
return targetObj;
}
function JSONCopy(source) {
return JSON.parse(JSON.stringify(source));
}