This file contains hidden or 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
<?php | |
/** | |
| The commented code shows the full code of the ternary equiv. | |
*/ | |
// if ($age = 20 < 22) | |
// { |
This file contains hidden or 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 data = [ | |
{id: 1, title: "Don't Waste your life ", price: 33, Author: "John Piper"}, | |
{id: 2, title: "Living for a greater purpose", price: 12, Author: "JH Baritam"}, | |
{id: 3, title: "The call for Mercy", price: 405, Author: "Lekia Yiga"}, | |
{id: 4, title: "Heart Blindness", price: 550, Author: "Unknown author"} | |
]; |
This file contains hidden or 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 newPrice = data.map((book) => book.price + 200); | |
console.log(newPrice); | |
// result: | |
// (4) [233, 212, 605, 750] |
This file contains hidden or 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
data.map(item => { | |
if (item.price > 100) { | |
return { | |
id: item.id, | |
title: item.title, | |
price: item.price * (1 - 0.2) | |
}; | |
} | |
return item; | |
}); |
This file contains hidden or 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 data = [ | |
{id: 1, title: "Don't Waste your life ", price: 33, Author: "John Piper"}, | |
{id: 2, title: "Living for a greater purpose", price: 12, Author: "JH Baritam"}, | |
{id: 3, title: "The call for Mercy", price: 405, Author: "Lekia Yiga"}, | |
{id: 4, title: "Heart Blindness", price: 550, Author: "Unknown author"} | |
]; | |
let discountedBooks = data.filter(item => item.price > 100); | |
console.log(discountedBooks); | |
//result | |
/* |
This file contains hidden or 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 data = [ | |
{id: 1, title: "Don't Waste your life ", price: 33, Author: "John Piper"}, | |
{id: 2, title: "Living for a greater purpose", price: 12, Author: "JH Baritam"}, | |
{id: 3, title: "The call for Mercy", price: 405, Author: "Lekia Yiga"}, | |
{id: 4, title: "Heart Blindness", price: 550, Author: "Unknown author"} | |
]; | |
let discountedBooks = data.find(item => item.price > 100); | |
console.log(discountedBooks); | |
// result |
This file contains hidden or 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 data = [ | |
{id: 1, title: 'Nite watch', price: 33, discount:0}, | |
{id: 2, title: 'what I want', price: 12, discount:0.4}, | |
{id: 3, title: 'Mercy at last', price: 405, discount:0.25}, | |
{id: 4, title: 'Nothting between', price: 550, discount:0} | |
]; | |
let discountedBooks = data.some(item => item.discount > 0 ); | |
console.log(discountedBooks); | |
// result |
This file contains hidden or 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 data = [ | |
{id: 1, title: 'Nite watch', price: 33, discount:0}, | |
{id: 2, title: 'what I want', price: 12, discount:0.4}, | |
{id: 3, title: 'Mercy at last', price: 405, discount:0.25}, | |
{id: 4, title: 'Nothting between', price: 550, discount:0} | |
]; | |
let discountedBooks = data.every(item => item.discount > 0 ); | |
console.log(discountedBooks); | |
// result |
This file contains hidden or 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 data = [ | |
{id: 1, title: 'Nite watch', price: 33, discount:0}, | |
{id: 2, title: 'what I want', price: 12, discount:0.4}, | |
{id: 3, title: 'Mercy at last', price: 405, discount:0.25}, | |
{id: 4, title: 'Nothting between', price: 550, discount:0} | |
]; | |
priceSum = data.reduce((acc, currentValue) => acc + currentValue.price, 0); | |
console.log(priceSum); | |
// console result | |
1000 |
This file contains hidden or 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
$permeabilityArray = [9230, 5940, 3080, 2860, 2790, 2370, 1464, 594, 593, 526, 500, 366]; | |
/** | |
* Each number in the array should take turns to divided it self and every other number in the array, | |
* and a number can only divide itself or a number that has index greater than it. | |
* E.g 9230 can divide itself and every other number. 3080 can not divide 5940, and 9230 but can divide | |
* 2860, 2790, 2370, 1464, 594, 593, 526, 500, and 366. | |
* Print result different set of arrays. | |
*/ |
OlderNewer